Skip to content

Commit

Permalink
Add analyze-bundles script
Browse files Browse the repository at this point in the history
This makes it easier to analyze bundles with webpack-bundle-analyzer,
which is already included as a project dependency.
  • Loading branch information
sgomes committed Apr 23, 2020
1 parent bb07685 commit 6b99217
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"worker-farm": "1.7.0"
},
"scripts": {
"analyze-bundles": "WP_BUNDLE_ANALYZER=true npm run build",
"prebuild": "npm run check-engines",
"clean:packages": "rimraf \"./packages/*/@(build|build-module|build-style)\"",
"clean:package-types": "tsc --build --clean",
Expand Down
12 changes: 11 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
const { DefinePlugin } = require( 'webpack' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
const postcss = require( 'postcss' );
Expand Down Expand Up @@ -38,7 +39,15 @@ const gutenbergPackages = Object.keys( dependencies )
)
.map( ( packageName ) => packageName.replace( WORDPRESS_NAMESPACE, '' ) );

const analyzingBundles =
process.env.WP_BUNDLE_ANALYZER &&
process.env.WP_BUNDLE_ANALYZER !== 'false';

module.exports = {
optimization: {
// Don't concatenate modules when analyzing bundles.
concatenateModules: ! analyzingBundles,
},
mode,
entry: gutenbergPackages.reduce( ( memo, packageName ) => {
const name = camelCaseDash( packageName );
Expand All @@ -62,6 +71,7 @@ module.exports = {
] ),
},
plugins: [
analyzingBundles && new BundleAnalyzerPlugin(),
new DefinePlugin( {
// Inject the `GUTENBERG_PHASE` global, used for feature flagging.
'process.env.GUTENBERG_PHASE': JSON.stringify(
Expand Down Expand Up @@ -189,7 +199,7 @@ module.exports = {
},
] ),
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
],
].filter( Boolean ),
watchOptions: {
ignored: '!packages/*/!(src)/**/*',
},
Expand Down

0 comments on commit 6b99217

Please sign in to comment.