Skip to content

Commit

Permalink
feat(webpack): add analyze flag to enable webpack bundle analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyGrant committed Feb 5, 2018
1 parent d32c443 commit 6ac3260
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/commands/new/buildsystems/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ module.exports = function(project, options) {
'json-loader',
'html-loader',
'istanbul-instrumenter-loader',
'opn'
'opn',
'webpack-bundle-analyzer'
).addToDependencies(
'aurelia-polyfills'
);
Expand Down
5 changes: 3 additions & 2 deletions lib/resources/content/webpack.config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const cssRules = [
// @endif
];

module.exports = ({production, server, extractCss, coverage} = {}) => ({
module.exports = ({production, server, extractCss, coverage, analyze} = {}) => ({
resolve: {
// @if transpiler.id='typescript'
extensions: ['.ts', '.js'],
Expand Down Expand Up @@ -191,6 +191,7 @@ module.exports = ({production, server, extractCss, coverage} = {}) => ({
])),
...when(production, new UglifyJsPlugin({
sourceMap: true
}))
})),
...when(analyze, new BundleAnalyzerPlugin())
]
});
3 changes: 2 additions & 1 deletion lib/resources/tasks/build-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import gulp from 'gulp';
import configureEnvironment from './environment';
import del from 'del';

const analyze = CLIOptions.hasFlag('analyze');
const buildOptions = new Configuration(project.build.options);
const production = CLIOptions.getEnvironment() === 'prod';
const server = buildOptions.isApplicable('server');
const extractCss = buildOptions.isApplicable('extractCss');
const coverage = buildOptions.isApplicable('coverage');

const config = webpackConfig({
production, server, extractCss, coverage
production, server, extractCss, coverage, analyze
});
const compiler = webpack(config);

Expand Down
21 changes: 21 additions & 0 deletions lib/resources/tasks/build-webpack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "build",
"description": "Builds and processes all application assets.",
"flags": [
{
"name": "analyze",
"description": "Enable Webpack Bundle Analyzer. Typically paired with --env prod",
"type": "boolean"
},
{
"name": "env",
"description": "Sets the build environment.",
"type": "string"
},
{
"name": "watch",
"description": "Watches source files for changes and refreshes the bundles automatically.",
"type": "boolean"
}
]
}
3 changes: 2 additions & 1 deletion lib/resources/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import * as gulp from 'gulp';
import configureEnvironment from './environment';
import * as del from 'del';

const analyze = CLIOptions.hasFlag('analyze');
const buildOptions = new Configuration(project.build.options);
const production = CLIOptions.getEnvironment() === 'prod';
const server = buildOptions.isApplicable('server');
const extractCss = buildOptions.isApplicable('extractCss');
const coverage = buildOptions.isApplicable('coverage');

const config = webpackConfig({
production, server, extractCss, coverage
production, server, extractCss, coverage, analyze
});
const compiler = webpack(<any>config);

Expand Down
13 changes: 9 additions & 4 deletions lib/resources/tasks/run-webpack.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
"name": "run",
"description": "Builds the application and serves up the assets via a local web server, watching files for changes as you work.",
"flags": [
{
"name": "analyze",
"description": "Enable Webpack Bundle Analyzer. Typically paired with --env prod",
"type": "boolean"
},
{
"name": "env",
"description": "Sets the build environment.",
"type": "string"
},
{
"name": "watch",
"description": "Watches source files for changes and refreshes the app automatically.",
"name": "hmr",
"description": "Enable Hot Module Reload",
"type": "boolean"
},
{
"name": "hmr",
"description": "Enable Hot Module Reload",
"name": "watch",
"description": "Watches source files for changes and refreshes the app automatically.",
"type": "boolean"
}
]
Expand Down

0 comments on commit 6ac3260

Please sign in to comment.