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

Build tools: Use Webpack splitChunks feature to extract duplicated babel runtime #9275

Closed
wants to merge 2 commits into from

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Aug 23, 2018

Description

I followed Webpack docs: https://webpack.js.org/plugins/split-chunks-plugin/.

It looks like this decresases the size of the bundles produced by Webpack by ~25%. I need to calculate it again. It would be great to use some tools instead :)

Todo tasks and open questions

  • Fix different chunk name for development (build/babel-runtime/babel-runtime.index.js) and production (build/babel-runtime/0.index.js)
  • How to enable those polyfills for all individual modules? Include them everywhere? This is what this PR does at the moment

Before

                                       Asset       Size  Chunks                    Chunk Names
                     ./build/blocks/index.js    225 KiB      23  [emitted]         blocks
                  ./build/wordcount/index.js     10 KiB       0  [emitted]         wordcount
                        ./build/url/index.js   20.6 KiB       2  [emitted]         url
                 ./build/token-list/index.js   16.1 KiB       3  [emitted]         tokenList
                  ./build/shortcode/index.js   16.2 KiB       4  [emitted]         shortcode
              ./build/redux-routine/index.js   18.6 KiB       5  [emitted]         reduxRoutine
                    ./build/plugins/index.js   24.5 KiB       6  [emitted]         plugins
                        ./build/nux/index.js   27.6 KiB       7  [emitted]         nux
                   ./build/keycodes/index.js   14.8 KiB       8  [emitted]         keycodes
           ./build/is-shallow-equal/index.js   1.15 KiB       9  [emitted]         isShallowEqual
                       ./build/i18n/index.js   27.4 KiB      10  [emitted]         i18n
              ./build/html-entities/index.js  986 bytes      11  [emitted]         htmlEntities
                      ./build/hooks/index.js   19.3 KiB      12  [emitted]         hooks
                    ./build/element/index.js     39 KiB      13  [emitted]         element
                     ./build/editor/index.js    340 KiB      14  [emitted]  [big]  editor
                  ./build/dom-ready/index.js  778 bytes      15  [emitted]         domReady
                        ./build/dom/index.js   22.6 KiB      16  [emitted]         dom
                 ./build/deprecated/index.js   10.8 KiB      17  [emitted]         deprecated
                       ./build/date/index.js    192 KiB      18  [emitted]         date
                       ./build/data/index.js   66.1 KiB      19  [emitted]         data
                  ./build/core-data/index.js   75.3 KiB      20  [emitted]         coreData
                    ./build/compose/index.js   32.4 KiB      21  [emitted]         compose
                   ./build/viewport/index.js   24.3 KiB       1  [emitted]         viewport
                       ./build/blob/index.js  909 bytes      24  [emitted]         blob
                      ./build/autop/index.js   29.3 KiB      25  [emitted]         autop
                  ./build/api-fetch/index.js   40.6 KiB      26  [emitted]         apiFetch
                       ./build/a11y/index.js   5.32 KiB      27  [emitted]         a11y
                ./build/core-blocks/index.js  994 bytes      28  [emitted]         coreBlocks
              ./build/block-library/index.js    209 KiB      29  [emitted]         blockLibrary
                  ./build/edit-post/index.js   85.1 KiB      30  [emitted]         editPost
                 ./build/components/index.js    500 KiB      31  [emitted]  [big]  components

./build/block-serialization-spec-parser/index.js 9.48 KiB 22 [emitted] blockSerializationSpecParser

Total: ~2 100 kB (before gzip)

screen shot 2018-08-23 at 15 21 56

After

                                       Asset       Size                        Chunks                    Chunk Names
           ./build/is-shallow-equal/index.js   1.15 KiB                isShallowEqual  [emitted]         isShallowEqual
                       ./build/a11y/index.js   2.36 KiB                          a11y  [emitted]         a11y
                      ./build/autop/index.js   6.43 KiB                         autop  [emitted]         autop
./build/babel-runtime/babel-runtime.index.js   75.8 KiB                 babel-runtime  [emitted]         babel-runtime
                       ./build/blob/index.js  909 bytes                          blob  [emitted]         blob
              ./build/block-library/index.js    173 KiB                  blockLibrary  [emitted]         blockLibrary
                     ./build/blocks/index.js    178 KiB                        blocks  [emitted]         blocks
                 ./build/components/index.js    451 KiB                    components  [emitted]  [big]  components
                    ./build/compose/index.js   6.17 KiB                       compose  [emitted]         compose
                ./build/core-blocks/index.js  992 bytes                    coreBlocks  [emitted]         coreBlocks
                  ./build/core-data/index.js   24.5 KiB                      coreData  [emitted]         coreData
                       ./build/data/index.js   21.5 KiB                          data  [emitted]         data
                       ./build/date/index.js    188 KiB                          date  [emitted]         date
                 ./build/deprecated/index.js   1.69 KiB                    deprecated  [emitted]         deprecated
                        ./build/dom/index.js   7.57 KiB                           dom  [emitted]         dom
                  ./build/dom-ready/index.js  778 bytes                      domReady  [emitted]         domReady
                  ./build/edit-post/index.js   53.8 KiB                      editPost  [emitted]         editPost
                     ./build/editor/index.js    288 KiB                        editor  [emitted]  [big]  editor
                    ./build/element/index.js    6.9 KiB                       element  [emitted]         element
                      ./build/hooks/index.js   4.99 KiB                         hooks  [emitted]         hooks
              ./build/html-entities/index.js  986 bytes                  htmlEntities  [emitted]         htmlEntities
                       ./build/i18n/index.js   19.2 KiB                          i18n  [emitted]         i18n
                  ./build/api-fetch/index.js    4.1 KiB                      apiFetch  [emitted]         apiFetch
                   ./build/keycodes/index.js   3.48 KiB                      keycodes  [emitted]         keycodes
                        ./build/nux/index.js   6.92 KiB                           nux  [emitted]         nux
                    ./build/plugins/index.js   4.21 KiB                       plugins  [emitted]         plugins
              ./build/redux-routine/index.js   1.75 KiB                  reduxRoutine  [emitted]         reduxRoutine
                  ./build/shortcode/index.js   4.14 KiB                     shortcode  [emitted]         shortcode
                 ./build/token-list/index.js   2.52 KiB                     tokenList  [emitted]         tokenList
                        ./build/url/index.js   8.86 KiB                           url  [emitted]         url
                   ./build/viewport/index.js   2.86 KiB                      viewport  [emitted]         viewport
                  ./build/wordcount/index.js    3.1 KiB                     wordcount  [emitted]         wordcount

./build/block-serialization-spec-parser/index.js 9.48 KiB blockSerializationSpecParser [emitted] blockSerializationSpecParser

Total: ~1 580 kB (before gzip)

screen shot 2018-08-29 at 12 54 31

How has this been tested?

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@gziolo gziolo self-assigned this Aug 23, 2018
@gziolo gziolo added [Type] Build Tooling Issues or PRs related to build tooling [Status] In Progress Tracking issues with work in progress [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible labels Aug 23, 2018
@gziolo gziolo force-pushed the update/webpack-split-chunks branch from 0a9cd49 to 9a90705 Compare August 29, 2018 11:12
@gziolo gziolo removed the [Status] In Progress Tracking issues with work in progress label Aug 29, 2018
@gziolo
Copy link
Member Author

gziolo commented Aug 29, 2018

I fixed the issue with the name of the chunk which collects all Babel related dependencies:

  • @babel/runtime-corejs2
  • core-js
  • regenerator-runtime

Kudos to @jsnajdr for the great hint 👍

@gziolo gziolo added this to the 3.8 milestone Aug 30, 2018
@gziolo gziolo force-pushed the update/webpack-split-chunks branch from 9a90705 to 674d55a Compare August 30, 2018 11:36
@youknowriad youknowriad removed this from the 3.8 milestone Sep 5, 2018
@gziolo
Copy link
Member Author

gziolo commented Sep 6, 2018

An alternative solution was proposed by @aduth in #9643. Let's focus on that one instead.

@gziolo gziolo closed this Sep 6, 2018
@gziolo gziolo deleted the update/webpack-split-chunks branch September 6, 2018 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants