Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disable Code Splitting (and caching) In Create React App
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;
"start": "node ./scripts/start-non-split.js",
"build": "node ./scripts/build-non-split.js",
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;
})
@simpixelated

This comment has been minimized.

Copy link
Owner Author

simpixelated commented Apr 23, 2019

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 on npm run start and npm 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!

@juffalow

This comment has been minimized.

Copy link

juffalow commented Nov 5, 2019

Thank you for this solutions! Is there an option not to use rewire package? So that I do not have to install new package.

@simpixelated

This comment has been minimized.

Copy link
Owner Author

simpixelated commented Nov 5, 2019

@juffalow sure, you can create your own version of the rewire package: https://github.com/jhnns/rewire/blob/master/lib/rewire.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.