excalidraw/scripts/build-node.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-01-19 22:21:33 +01:00
#!/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
2020-01-19 22:21:33 +01:00
// 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");
2020-01-19 22:21:33 +01:00
// Disable multiple chunks
config.optimization.runtimeChunk = false;
config.optimization.splitChunks = {
cacheGroups: {
2020-01-24 11:04:54 +01:00
default: false,
},
2020-01-19 22:21:33 +01:00
};
// 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";
2020-01-19 22:21:33 +01:00
// 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.
2020-11-06 21:06:39 +01:00
config.externals = (context, request, callback) => {
2020-01-19 22:21:33 +01:00
if (/\.node$/.test(request)) {
return callback(
null,
2020-01-24 11:04:54 +01:00
"commonjs ../../../node_modules/canvas/build/Release/canvas.node",
2020-01-19 22:21:33 +01:00
);
}
callback();
};