build-node.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env node
  2. // In order to use this, you need to install Cairo on your machine. See
  3. // instructions here: https://github.com/Automattic/node-canvas#compiling
  4. // In order to run:
  5. // npm install canvas # please do not check it in
  6. // yarn build-node
  7. // node build/static/js/build-node.js
  8. // open test.png
  9. const rewire = require("rewire");
  10. const defaults = rewire("react-scripts/scripts/build.js");
  11. const config = defaults.__get__("config");
  12. // Disable multiple chunks
  13. config.optimization.runtimeChunk = false;
  14. config.optimization.splitChunks = {
  15. cacheGroups: {
  16. default: false,
  17. },
  18. };
  19. // Set the filename to be deterministic
  20. config.output.filename = "static/js/build-node.js";
  21. // Don't choke on node-specific requires
  22. config.target = "node";
  23. // Set the node entrypoint
  24. config.entry = "./src/index-node";
  25. // By default, webpack is going to replace the require of the canvas.node file
  26. // to just a string with the path of the canvas.node file. We need to tell
  27. // webpack to avoid rewriting that dependency.
  28. config.externals = (context, request, callback) => {
  29. if (/\.node$/.test(request)) {
  30. return callback(
  31. null,
  32. "commonjs ../../../node_modules/canvas/build/Release/canvas.node",
  33. );
  34. }
  35. callback();
  36. };