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

Bundle Optimization #53

Merged
merged 6 commits into from
Jul 13, 2018
Merged

Bundle Optimization #53

merged 6 commits into from
Jul 13, 2018

Conversation

heathharrelson
Copy link
Member

I spent some time yesterday comparing the bundles of the master branch and the vue branch using webpack-bundle-analyzer and found a couple of interesting things:

  • Moment.js is around 25% of our bundle (see Optimize or Replace Moment.js #51) and Chart.js includes a second copy of it.
  • The bundle includes the full version of Vue.js (with template compiler), even though we're using vue-loader to pre-compile our templates.

This PR makes the following optimizations:

  • Use the standalone version of Chart.js, which doesn't bundle Moment.js. Chart.js only uses moment when axis values are date objects. This isn't relevant in our case, because Vizr formats dates to strings before handing them off to Chart.js.
  • Change the root of the Vue tree's template to a render function so we can bundle the runtime-only version of Vue.js.

With these changes, the vue branch's bundle is around 100 KB smaller than master when uncompressed (10 KB smaller compressed). We may get additional improvements by upgrading to Webpack 4.

Add a item to `package.json`'s `scripts` block to build the app
and run the bundle analyzer on it.
Use the runtime-only version of Vue.js (minus the template compiler)
to reduce the size of the bundle. The template compiler was only
needed because of the string template in the Vue.js root, which
is easily converted to a render function.
Update the arguments used to build the application when analyzing
to ensure Vue's production mode is enabled.
Add `bundle-stats.json` to the list of files deleted by the clean
script.
Use the standalone release of Chart.js. This removes the unused
second copy of Moment.js from our bundle.
@@ -26,7 +26,14 @@ export function run(pid, canEdit, jsonAssetUrls) {
new Vue({
el: '.vizr-container',
components: { Vizr },
Copy link
Member Author

Choose a reason for hiding this comment

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

The root component is the only one with a template string (all the others are single-file components processed by vue-loader), which is why the template compiler was required at runtime. This equivalent render function allows removing the compiler from our bundle.

This change could also be made to phenotypr-body.

@@ -65,6 +67,7 @@ module.exports = {
devtool: 'cheap-source-map',
plugins: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(buildEnv),
Copy link
Member Author

Choose a reason for hiding this comment

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

Allows Vue.js build process to strip out development-mode code. See the Vue.js deployment guide.

@heathharrelson heathharrelson merged commit dfe5e0e into vue Jul 13, 2018
@heathharrelson heathharrelson deleted the bundle-optimization branch July 13, 2018 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants