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

How to disable split chunk in build #13906

Closed
nsisodiya opened this issue May 7, 2019 · 5 comments
Closed

How to disable split chunk in build #13906

nsisodiya opened this issue May 7, 2019 · 5 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@nsisodiya
Copy link

How to disable code splitting. I tried but unable to find suitable settings.

@gatsbot gatsbot bot added the type: question or discussion Issue discussing or asking a question about Gatsby label May 7, 2019
@nsisodiya
Copy link
Author

nsisodiya commented May 7, 2019

I tried this one.

gatsby-node.js

const webpack = require(`webpack`);

exports.onCreateWebpackConfig = ({ stage, actions }, options) => {
  console.log('==== Disabling Chunk ====');
  if ((process.env.NODE_ENV === 'production' && stage === 'build-javascript') || options.development) {
    actions.setWebpackConfig({
      plugins: [
        new webpack.optimize.LimitChunkCountPlugin({
          maxChunks: 1
        })
      ]
    });
  }
};

@trevorlitsey
Copy link
Contributor

trevorlitsey commented May 8, 2019

hi @nsisodiya, would this work for your needs?

exports.onCreateWebpackConfig = () => {
  actions.setWebpackConfig({
    optimization: {
      splitChunks: false,
    },
  });
};

From what I can tell (I think) Gatsby creates an entry file for each of your pages, which will create additional JS files in addition to app.js. This is a separate Webpack step from chunking. So if you have more than one page in your src/pages directory, you will end up with more than one js file even with this setting on. If you keep just one index.js file in src/pages, and use the snippet above, this will get you close to one file for your app.

@nsisodiya
Copy link
Author

@trevorlitsey - I tried, but it didn't worked.

@nsisodiya nsisodiya reopened this May 8, 2019
@LekoArts
Copy link
Contributor

LekoArts commented May 8, 2019

As mentioned in your other issue we don't recommend changing this behavior of Gatsby. We work hard on making Gatsby as fast as possible and this would decrease your speed. Hence I'm closing this, thanks for the issue!

@LekoArts LekoArts closed this as completed May 8, 2019
@slorber
Copy link
Contributor

slorber commented Aug 14, 2019

@LekoArts what about actually "enhancing" the gatsby config? Is this not recommended when gatsby config does not totally suit us?

For example see this #10965 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants