Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add analyze-bundles script #21827

Merged
merged 5 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "cross-env WP_BUNDLE_ANALYZER=1 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
1 change: 1 addition & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Breaking Changes

- The bundled `puppeteer` (`^2.0.0`) dependency has been replaced with `puppeteer-core` in version `3.0.0`. Puppeteer uses Chromium v81 instead of Chromium v79. See the [full list of changes](https://github.com/puppeteer/puppeteer/releases/tag/v3.0.0). It also allowed preventing Chromium installation together with `@wordpress/scripts`. It happens now on-demand when running `test-e2e` script, and it re-triggers only when a new version is required.
- Bundle analysis now runs with module concatenation disabled. This represents the size of individual modules more accurately, at the cost of not providing an exact byte-for-byte match to the final size in the production chunk.
Copy link
Member

@gziolo gziolo May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you merged this change without rebasing. It ended up in the section that was already published to npm:

https://github.com/WordPress/gutenberg/blob/master/packages/scripts/CHANGELOG.md#900-2020-04-30

Also, it doesn't look like a breaking change, or is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I did do that, yes. Whether it's a breaking change or not depends on interpretation; if we consider the bundle analysis to be part of the scripts package "user contract", then this is a breaking change, otherwise it's not.

Shall I prepare a PR moving this to the right section and making it a non-breaking change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be great 👍


### New Features

Expand Down
9 changes: 7 additions & 2 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';

const config = {
optimization: {
// Only concatenate modules in production, when not analyzing bundles.
concatenateModules:
mode === 'production' && ! process.env.WP_BUNDLE_ANALYZER,
},
Comment on lines +22 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a relevant entry we should mention in scripts/CHANGELOG.md ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an entry 👍

mode,
entry: {
index: path.resolve( process.cwd(), 'src', 'index.js' ),
Expand Down Expand Up @@ -70,8 +75,8 @@ const config = {
],
},
plugins: [
// WP_BUNDLE_ANALYZER global variable enables utility that represents bundle content
// as convenient interactive zoomable treemap.
// The WP_BUNDLE_ANALYZER global variable enables a utility that represents bundle
// content as a convenient interactive zoomable treemap.
process.env.WP_BUNDLE_ANALYZER && new BundleAnalyzerPlugin(),
// WP_LIVE_RELOAD_PORT global variable changes port on which live reload works
// when running watch mode.
Expand Down
11 changes: 10 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 @@ -39,6 +40,11 @@ const gutenbergPackages = Object.keys( dependencies )
.map( ( packageName ) => packageName.replace( WORDPRESS_NAMESPACE, '' ) );

module.exports = {
optimization: {
// Only concatenate modules in production, when not analyzing bundles.
concatenateModules:
mode === 'production' && ! process.env.WP_BUNDLE_ANALYZER,
},
mode,
entry: gutenbergPackages.reduce( ( memo, packageName ) => {
const name = camelCaseDash( packageName );
Expand All @@ -62,6 +68,9 @@ module.exports = {
] ),
},
plugins: [
// The WP_BUNDLE_ANALYZER global variable enables a utility that represents bundle
// content as a convenient interactive zoomable treemap.
process.env.WP_BUNDLE_ANALYZER && 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 +198,7 @@ module.exports = {
},
] ),
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
],
].filter( Boolean ),
watchOptions: {
ignored: '!packages/*/!(src)/**/*',
},
Expand Down