Skip to content

Commit

Permalink
perf(okam-build): optimize style dep resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhy committed Dec 15, 2018
1 parent c5a55cb commit 9aa7c75
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 42 deletions.
16 changes: 8 additions & 8 deletions packages/okam-build/lib/build/BuildManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,15 @@ class BuildManager extends EventEmitter {
ast && (file.ast = ast);

deps && deps.forEach(item => {
let depFile;
if (pathUtil.isAbsolute(item)) {
depFile = this.files.addFile(item);
}
else {
item = item.replace(/\\/g, '/');
depFile = this.files.getByPath(item);
depFile || (depFile = this.files.addFile({path: item}));
this.logger.debug('add dep', item);
if (!pathUtil.isAbsolute(item)) {
item = pathUtil.join(
pathUtil.dirname(file.fullPath), item
);
this.logger.debug('absolute dep', item);
}

let depFile = this.files.addFile(item);
file.addDeps(depFile.path);
this.addNeedBuildFile(depFile);
});
Expand Down
15 changes: 1 addition & 14 deletions packages/okam-build/lib/processor/css/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

const path = require('path');
const less = require('less');
const relative = require('../../util').file.relative;

module.exports = function (file, options) {
let {logger, config, root} = options;
Expand Down Expand Up @@ -35,19 +34,7 @@ module.exports = function (file, options) {
throw err;
}
processResult.content = result.css;

// normalize dep path relative to root
let deps = result.imports;
if (deps) {
deps = deps.map(
item => relative(path.join(
path.dirname(file.fullPath),
item
), root)
);
}

processResult.deps = deps;
processResult.deps = result.imports;
});
return processResult;
};
11 changes: 1 addition & 10 deletions packages/okam-build/lib/processor/css/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
const path = require('path');
const postcss = require('postcss');
const normalizePlugins = require('../helper/plugin');
const relative = require('../../util').file.relative;

const BUILTIN_PLUGINS = {
autoprefixer: {
Expand Down Expand Up @@ -65,17 +64,9 @@ module.exports = function (file, options) {
}
);

// normalize dep path relative to root
let deps = result.deps;
if (deps) {
deps = deps.map(
item => relative(path.join(path.dirname(file.fullPath), item), root)
);
}

return {
content: css,
deps
deps: result.deps
};
};

2 changes: 1 addition & 1 deletion packages/okam-build/lib/processor/css/stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const stylus = require('stylus');
module.exports = function (file, options) {
let config = options.config;
config = Object.assign({
filename: file.path
filename: file.fullPath
}, config);

// init the paths to search
Expand Down
12 changes: 3 additions & 9 deletions packages/okam-build/lib/processor/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/* eslint-disable fecs-min-vars-per-destructure */
/* eslint-disable fecs-prefer-destructure */
const path = require('path');
const {file: fileUtil} = require('../../util/index');
const {parse: parseDom} = require('./parser');
const serializeDom = require('./serializer');

Expand Down Expand Up @@ -167,14 +165,10 @@ function compileTpl(file, options) {

let deps = [];
let addDep = function (filePath) {
let relativePath = fileUtil.relative(
path.join(path.dirname(file.fullPath), filePath),
root
);
if (!deps.includes(relativePath)) {
deps.push(relativePath);
if (!deps.includes(filePath)) {
deps.push(filePath);
}
logger.debug('find tpl dep file', relativePath);
logger.debug('find tpl dep file', filePath);
};

transformAst(
Expand Down

0 comments on commit 9aa7c75

Please sign in to comment.