aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/build-node.js
diff options
context:
space:
mode:
authorkj_sh6042026-03-15 16:19:36 -0400
committerkj_sh6042026-03-15 16:19:36 -0400
commit72ece7c00b091011617fccf719df7f602cf4f7c7 (patch)
tree75a085594679b4282faac3b3646d589bf5a67ea5 /scripts/build-node.js
parentc142734224f6263180e4cbe6fabec591a27972a1 (diff)
refactor: scripts/
Diffstat (limited to 'scripts/build-node.js')
-rwxr-xr-xscripts/build-node.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/build-node.js b/scripts/build-node.js
new file mode 100755
index 0000000..b9bed01
--- /dev/null
+++ b/scripts/build-node.js
@@ -0,0 +1,40 @@
+#!/usr/bin/env node
+
+// In order to use this, you need to install Cairo on your machine. See
+// instructions here: https://github.com/Automattic/node-canvas#compiling
+
+// In order to run:
+// npm install canvas # please do not check it in
+// yarn build-node
+// node build/static/js/build-node.js
+// open test.png
+
+const rewire = require("rewire");
+const defaults = rewire("react-scripts/scripts/build.js");
+const config = defaults.__get__("config");
+
+// Disable multiple chunks
+config.optimization.runtimeChunk = false;
+config.optimization.splitChunks = {
+ cacheGroups: {
+ default: false,
+ },
+};
+// Set the filename to be deterministic
+config.output.filename = "static/js/build-node.js";
+// Don't choke on node-specific requires
+config.target = "node";
+// Set the node entrypoint
+config.entry = "../packages/excalidraw/index-node";
+// By default, webpack is going to replace the require of the canvas.node file
+// to just a string with the path of the canvas.node file. We need to tell
+// webpack to avoid rewriting that dependency.
+config.externals = (context, request, callback) => {
+ if (/\.node$/.test(request)) {
+ return callback(
+ null,
+ "commonjs ../../../node_modules/canvas/build/Release/canvas.node",
+ );
+ }
+ callback();
+};