build-react-no-split.js 1014 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env node
  2. /**
  3. * A script that overrides some of the create-react-app build script configurations
  4. * in order to disable code splitting/chunking and rename the output build files so
  5. * they have no hash. (Reference: https://mtm.dev/disable-code-splitting-create-react-app).
  6. *
  7. * This is crucial for getting React webview code to run because VS Code expects a
  8. * single (consistently named) JavaScript and CSS file when configuring webviews.
  9. */
  10. const rewire = require("rewire")
  11. const defaults = rewire("react-scripts/scripts/build.js")
  12. const config = defaults.__get__("config")
  13. // Disable code splitting
  14. config.optimization.splitChunks = {
  15. cacheGroups: {
  16. default: false,
  17. },
  18. }
  19. // Disable code chunks
  20. config.optimization.runtimeChunk = false
  21. // Rename main.{hash}.js to main.js
  22. config.output.filename = "static/js/[name].js"
  23. // Rename main.{hash}.css to main.css
  24. config.plugins[5].options.filename = "static/css/[name].css"
  25. config.plugins[5].options.moduleFilename = () => "static/css/main.css"