From a5425113096216d5cb0eb585d3c869a17ccff957 Mon Sep 17 00:00:00 2001 From: JiM-W <550116990@qq.com> Date: Mon, 9 Nov 2020 17:09:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=86=85=E7=BD=AE=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E5=BC=95=E7=94=A8=E7=9A=84=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- .../chameleon-tool/configs/getCommonConfig.js | 30 +++++++++++++++++++ packages/chameleon-tool/lib/config.js | 3 +- packages/chameleon-tool/npm-shrinkwrap.json | 5 ++++ packages/chameleon-tool/package.json | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 85348a27a..c6d5dcd10 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/packages/chameleon-tool/configs/getCommonConfig.js b/packages/chameleon-tool/configs/getCommonConfig.js index 676a46efb..87ff41136 100644 --- a/packages/chameleon-tool/configs/getCommonConfig.js +++ b/packages/chameleon-tool/configs/getCommonConfig.js @@ -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 { @@ -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)) } @@ -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({ diff --git a/packages/chameleon-tool/lib/config.js b/packages/chameleon-tool/lib/config.js index 40d793d9f..9d8247dbe 100644 --- a/packages/chameleon-tool/lib/config.js +++ b/packages/chameleon-tool/lib/config.js @@ -196,7 +196,8 @@ var chameleonConfig = { watchNodeModules: false, // 默认不对node_modules中的文件进行watch,提升编译性能 showWarning: false, // 为了兼容原来的配置,默认不开启构建过程中的警告信息,开启之后配合,DuplicatePackageCheckerPlugin 可以在构建过程中检查是否有重复npm包引入 dropConsole: true, - processBar: true + processBar: true, + circularDependency: true// 默认引入自动检测循环引用的插件 } } diff --git a/packages/chameleon-tool/npm-shrinkwrap.json b/packages/chameleon-tool/npm-shrinkwrap.json index 6f1189e5c..c3355eedc 100644 --- a/packages/chameleon-tool/npm-shrinkwrap.json +++ b/packages/chameleon-tool/npm-shrinkwrap.json @@ -3400,6 +3400,11 @@ "safe-buffer": "^5.0.1" } }, + "circular-dependency-plugin": { + "version": "4.4.0", + "resolved": "http://registry.npm.xiaojukeji.com/circular-dependency-plugin/download/circular-dependency-plugin-4.4.0.tgz", + "integrity": "sha1-+KGnRqP2yOV/Ta6bVNmRzSpYL10=" + }, "circular-json": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", diff --git a/packages/chameleon-tool/package.json b/packages/chameleon-tool/package.json index f7d96c720..bbffbe387 100644 --- a/packages/chameleon-tool/package.json +++ b/packages/chameleon-tool/package.json @@ -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",