Disable file chunking with CRACO
Asked Answered
P

2

5

I am trying to figure out how to use CRACO (https://github.com/gsoft-inc/craco) to disable file chunking in create react app.

I have created the following craco.config.js:

// craco.config.js
module.exports = {
  output: {
    fileName: 'static/js/bundle.js',
  },
}

But it doesn't have any effect. What should the config look like to disable file chunking in CRA with CRACO?

Polymerous answered 19/1, 2021 at 8:56 Comment(0)
S
13

EDIT: To disable chunking completely I believe this might do it.
Source: https://github.com/facebook/create-react-app/issues/5306#issuecomment-650737697

// craco.config.js
module.exports = {
  webpack: {
    configure: {
      optimization: {
        runtimeChunk: false,
        splitChunks: {
          chunks(chunk) {
            return false
          },
        },
      },
    },
  },
}

ORIGNIAL: Maybe this could help?

module.exports = {
  webpack: {
    configure: {
      output: {
        filename: 'static/js/bundle.js',
      },
      optimization: {
        runtimeChunk: false,
        splitChunks: {
          chunks: 'all',
          cacheGroups: {
            default: false,
            vendors: false,
            // vendor chunk
          },
        },
      },
    },
  },
  plugins: [
    {
      plugin: require('craco-plugin-scoped-css'),
    },
  ],
}
Sigil answered 19/1, 2021 at 9:1 Comment(6)
Thanks I now have a main bundle file but I am still getting 1 chunk file 1.hash.chunk.js. Any way to find out what this is from?Polymerous
@Polymerous I've updated the answer with a new solution, please let me know how it goes.Sigil
Thanks, the edit still gave one chunk file but reading the linked github thread had answer that this file is being created by reportWebVitals. Commenting that out results in a single bundle filePolymerous
@Polymerous nice one!Sigil
amazeballs! You saved my bacon. AFAICT craco isn't updating the serviceworker __WB_MANIFEST valriable with more than one chunk!Guiscard
actually this solution continues to have the wrong values for WB_MANIFESTGuiscard
N
0

follow the new solution in the github comments. I use this in my craco.config.cjs:

module.exports = {
  webpack: {
    configure: {
      plugins: [
        new webpack.optimize.LimitChunkCountPlugin({
          maxChunks: 1,
        })
      ]
    }
  },
  plugins: [{ plugin: CracoEsbuildPlugin }]
};

It works at @craco/craco 7.0.0

Neilson answered 18/8, 2023 at 14:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.