Skip to content

Commit

Permalink
feat: 内置支持循环引用的检测
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwmg committed Nov 9, 2020
1 parent 8048f25 commit a542511
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"dependencies": {
Expand Down
30 changes: 30 additions & 0 deletions packages/chameleon-tool/configs/getCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const fs = require('fs');
const cmlUtils = require('chameleon-tool-utils');
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');

module.exports = function (options) {
let {
Expand Down Expand Up @@ -176,6 +177,9 @@ module.exports = function (options) {
if (chameleonConfig.optimize && chameleonConfig.optimize.processBar) {
commonConfig.plugins.push(new ProgressBarPlugin())
}
if (chameleonConfig.optimize && chameleonConfig.optimize.circularDependency) {
commonConfig.plugins.push(new ProgressBarPlugin())
}
if (options.definePlugin) {
commonConfig.plugins.push(new webpack.DefinePlugin(options.definePlugin))
}
Expand Down Expand Up @@ -214,6 +218,32 @@ module.exports = function (options) {
verbose: true
})
);

commonConfig.plugins.push(
new DuplicatePackageCheckerPlugin({
verbose: true
})
);
if (chameleonConfig.optimize && chameleonConfig.optimize.circularDependency) {
commonConfig.plugins.push(
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /node_modules/,
// include specific files based on a RegExp
include: /src/,
// add errors to webpack instead of warnings
failOnError: true,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: false,
// set the current working directory for displaying module paths
cwd: process.cwd()
})
);


}

}
// 兼容旧版api
commonConfig.plugins.push(new webpack.DefinePlugin({
Expand Down
3 changes: 2 additions & 1 deletion packages/chameleon-tool/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ var chameleonConfig = {
watchNodeModules: false, // 默认不对node_modules中的文件进行watch,提升编译性能
showWarning: false, // 为了兼容原来的配置,默认不开启构建过程中的警告信息,开启之后配合,DuplicatePackageCheckerPlugin 可以在构建过程中检查是否有重复npm包引入
dropConsole: true,
processBar: true
processBar: true,
circularDependency: true// 默认引入自动检测循环引用的插件
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/chameleon-tool/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/chameleon-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"chameleon-vue-precompiler": "^1.0.8-alpah.1",
"chameleon-webpack-plugin": "^1.0.8-alpah.1",
"chameleon-weex-vue-loader": "^1.0.8-alpah.1",
"circular-dependency-plugin": "^4.4.0",
"clean-webpack-plugin": "0.1.19",
"cml-extract-css-webpack-plugin": "^1.0.8-alpah.1",
"cml-vue-loader": "^1.0.8-alpah.1",
Expand Down

0 comments on commit a542511

Please sign in to comment.