Last active
March 9, 2021 11:26
-
-
Save simpixelated/90a3c16c3ed268fe24f5e5c9585ced2f to your computer and use it in GitHub Desktop.
Disable Code Splitting (and caching) In Create React App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rewire = require('rewire'); | |
const defaults = rewire('react-scripts/scripts/build.js'); | |
let config = defaults.__get__('config'); | |
config.optimization.splitChunks = { | |
cacheGroups: { | |
default: false, | |
}, | |
}; | |
config.optimization.runtimeChunk = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"start": "node ./scripts/start-non-split.js", | |
"build": "node ./scripts/build-non-split.js", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rewire = require('rewire'); | |
const defaults = rewire('react-scripts/scripts/start.js'); | |
let configFactory = defaults.__get__('configFactory'); | |
defaults.__set__('configFactory', (env) => { | |
const config = configFactory(env); | |
config.optimization.splitChunks = { | |
cacheGroups: { | |
default: false, | |
}, | |
}; | |
config.optimization.runtimeChunk = false; | |
return config; | |
}) |
Thank you for this solutions! Is there an option not to use rewire
package? So that I do not have to install new package.
@juffalow sure, you can create your own version of the rewire package: https://github.com/jhnns/rewire/blob/master/lib/rewire.js
Hi I am getting these errors constantly
Error: Cannot find module 'react-scripts/scripts/start.js'
in case of disabling codesplitting
@Abraham-william I haven't had time to maintain this, so there may have been updates to create-react-app that need to be accounted for. Please check this issue: facebook/create-react-app#5306
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because ejecting can introduce much more complexity to your project than you might anticipate, it should be avoided. However, if you want to output a single
bundle.js
onnpm run start
andnpm run build
, you'll need to use the above scripts to override the default config until this issue is fixed.View it in action in https://github.com/ghost-inspector/wordpress-plugin
Thanks to GitHub user vonkanehoffen for this solution!