-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-react-no-split.js
31 lines (27 loc) · 1.15 KB
/
build-react-no-split.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
// FROM: https://github.com/microsoft/vscode-webview-ui-toolkit-samples/tree/main/frameworks/hello-world-react-cra
/**
* A script that overrides some of the create-react-app build script configurations
* in order to disable code splitting/chunking and rename the output build files so
* they have no hash. (Reference: https://mtm.dev/disable-code-splitting-create-react-app).
*
* This is crucial for getting React webview code to run because VS Code expects a
* single (consistently named) JavaScript and CSS file when configuring webviews.
*/
const rewire = require("rewire");
const defaults = rewire("react-scripts/scripts/build.js");
const config = defaults.__get__("config");
// Disable code splitting
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
// Disable code chunks
config.optimization.runtimeChunk = false;
config.optimization.minimize = false;
// Rename main.{hash}.js to main.js
config.output.filename = "static/js/[name].js";
// Rename main.{hash}.css to main.css
config.plugins[5].options.filename = "static/css/[name].css";
config.plugins[5].options.moduleFilename = () => "static/css/main.css";