This example demonstrates disabling code splitting when building an app created with Create React App 2. The build will output a single CSS file and a single JS file. A simple cache-busting parameter is automatically added to the file references within index.html.
Rewire will allow us to override certain variables and values in the configuration.
npm install rewire
yarn add rewire
For this example we have created a folder scripts
in the root of our React app, and placed the build-non-split.js
file inside it. See scripts/build-non-split.js
in this repo.
Note: the cacheBust
parameter will be added to the file references in index.html
, but is removed from the actual file names.
Modify the build script in package.json
to run our new file.
"scripts": {
...
"build": "node scripts/build-non-split.js",
...
}
The next time you perform a build you should see a single CSS file and a single JS file, both named "app".
Much of this example was derived from the discussion for Create React App issue 5306, specifically comments by vonkanehoffen, jw-afc, and illepic.
Comments by vincerubinetti found in issue 5306.
MIT License