Skip to content

Commit

Permalink
feat: add --analyze flag
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Oct 3, 2020
1 parent 55d0bd8 commit e1c942b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/webpack-cli/lib/groups/AdvancedGroup.js
@@ -1,3 +1,6 @@
const { packageExists, promptInstallation } = require('@webpack-cli/package-utils');
const { yellow } = require('colorette');
const { error } = require('../utils/logger');
const GroupHelper = require('../utils/GroupHelper');

class AdvancedGroup extends GroupHelper {
Expand Down Expand Up @@ -31,9 +34,26 @@ class AdvancedGroup extends GroupHelper {
if (args.target) {
options.target = args.target;
}
if (args.analyze) {
if (packageExists('webpack-bundle-analyzer')) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const bundleAnalyzerVal = new BundleAnalyzerPlugin();
if (options && options.plugins) {
options.plugins.unshift(bundleAnalyzerVal);
} else {
options.plugins = [bundleAnalyzerVal];
}
} else {
//prompt installation
promptInstallation('webpack-bundle-analyzer', () => {
error(`It looks like ${yellow('webpack-bundle-analyzer')} is not installed.`);
});
}
}
}
run() {
this.resolveOptions();
console.log(this.opts);
return this.opts;
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/webpack-cli/lib/utils/cli-flags.js
Expand Up @@ -222,6 +222,14 @@ const core = [
multiple: true,
description: 'Name of the configuration to use',
},
{
name: 'analyze',
usage: '--analyze',
type: Boolean,
multiple: false,
group: ADVANCED_GROUP,
description: 'Name of the configuration to use',
},
/* {
name: "analyze",
type: Boolean,
Expand Down
8 changes: 7 additions & 1 deletion packages/webpack-cli/package.json
Expand Up @@ -23,9 +23,9 @@
"web"
],
"dependencies": {
"@webpack-cli/package-utils": "^1.0.1-rc.0",
"@webpack-cli/info": "^1.0.1-rc.0",
"@webpack-cli/init": "^1.0.1-rc.0",
"@webpack-cli/package-utils": "^1.0.1-rc.0",
"@webpack-cli/serve": "^1.0.1-rc.0",
"ansi-escapes": "^4.3.1",
"colorette": "^1.2.1",
Expand All @@ -37,10 +37,16 @@
"interpret": "^2.0.0",
"rechoir": "^0.7.0",
"v8-compile-cache": "^2.1.0",
"webpack-bundle-analyzer": "^3.9.0",
"webpack-merge": "^4.2.2"
},
"peerDependencies": {
"webpack": "4.x.x || 5.x.x"
},
"peerDependenciesMeta": {
"webpack-bundle-analyzer": {
"optional": true
}
},
"gitHead": "fb50f766851f500ca12867a2aa9de81fa6e368f9"
}

0 comments on commit e1c942b

Please sign in to comment.