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

Code splitting: wrong config for commons chunk in webpack.config.js #22749

Closed
xsq007 opened this issue Apr 2, 2020 · 2 comments · Fixed by #22879
Closed

Code splitting: wrong config for commons chunk in webpack.config.js #22749

xsq007 opened this issue Apr 2, 2020 · 2 comments · Fixed by #22879
Assignees
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@xsq007
Copy link

xsq007 commented Apr 2, 2020

Description

The dynamic-imported script is included in commons chunk.
Looking at configuration for commons chunk in webpack.config.js.

commons: {
          name: `commons`,
          // if a chunk is used on all components we put it in commons
          minChunks: componentsCount,
          priority: 20
        },

Now above componentsCount is 1, so all dynamic components are included in commons chunk.
I think componentsCount should be at least 2. Another way is to set test function for commons to include all files from node_modules except those in frameworks chunk.

By the way, test function uses module.identifier() method. Is module.resource field better?

Steps to reproduce

  1. import some-script with import() method
import Loadable from 'react-loadable'

const MyComponent = Loadable({
  loader: () => import('./some-script'),
  loading: <div />,
})
  1. After building, the above some-script is included in commons chunk instead of a separate chunk file.

Expected result

This dynamic-imported script should be a separate chunk

Actual result

It is included in commons chunk now.

Environment

System:
OS: macOS 10.15.3
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 80.0.3987.149
Safari: 13.0.5
npmPackages:
gatsby: ^2.20.10 => 2.20.10
gatsby-link: ^2.2.27 => 2.3.1
gatsby-plugin-algolia: ^0.5.0 => 0.5.0
gatsby-plugin-gtag: ^1.0.12 => 1.0.13
gatsby-plugin-layout: ^1.1.18 => 1.2.1
gatsby-plugin-mdx: ^1.0.61 => 1.1.4
gatsby-plugin-no-sourcemaps: ^2.1.2 => 2.2.0
gatsby-plugin-offline: ^3.0.29 => 3.1.2
gatsby-plugin-postcss: ^2.1.20 => 2.2.1
gatsby-plugin-react-helmet: ^3.1.18 => 3.2.1
gatsby-plugin-remove-serviceworker: ^1.0.0 => 1.0.0
gatsby-plugin-remove-trailing-slashes: ^2.1.17 => 2.2.1
gatsby-plugin-sitemap: ^2.2.24 => 2.3.1
gatsby-remark-attr: 0.0.3 => 0.0.3
gatsby-remark-copy-linked-files: ^2.1.33 => 2.2.1
gatsby-source-filesystem: ^2.1.42 => 2.2.2
gatsby-transformer-remark: ^2.6.42 => 2.7.1

@xsq007 xsq007 added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 2, 2020
@wardpeet wardpeet self-assigned this Apr 2, 2020
@wardpeet
Copy link
Contributor

wardpeet commented Apr 7, 2020

Thanks @xsq007 for reporting, I improved our config to fix your issue.

@xsq007
Copy link
Author

xsq007 commented Apr 13, 2020

Thanks @xsq007 for reporting, I improved our config to fix your issue.

Thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants