-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-overrides.js
64 lines (57 loc) · 1.73 KB
/
config-overrides.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const fs = require("fs");
const path = require("path");
//const cmd = require("node-cmd");
//node_modules\react-scripts\config\webpack.config.js
let watcherObj = path.join(__dirname, "./src/rust");
try {
let status = false;
let statusTimeout;
let myWatcher = fs.watch(watcherObj, { encoding: "utf8", recursive: true }, (event, filename) => {
//console.log(event);
});
myWatcher.on("change", function (err, filename) {
if (filename.indexOf(".rs") > -1) {
if (!status) {
status = true;
//cmd.run("npm run wasm");
statusTimeout = setTimeout(() => {
status = false;
clearTimeout(statusTimeout);
}, 5000);
}
}
});
} catch (error) {
//console.log("err");
}
module.exports = function override(config, env) {
const wasmExtensionRegExp = /\.wasm$/;
let ext = config.resolve.extensions;
config.resolve.extensions = ext.concat([".ts", ".tsx", ".wasm", ".css"]);
config.resolve.plugins.splice(1, 1);
config.module.rules.forEach((rule) => {
(rule.use || []).forEach((use) => {
if (use.options && use.options.useEslintrc !== undefined) {
use.options.useEslintrc = true;
}
});
(rule.oneOf || []).forEach((oneOf) => {
if (oneOf.options && oneOf.options.babelrc !== undefined) {
oneOf.options.babelrc = true;
}
if (oneOf.loader && oneOf.loader.indexOf("file-loader") >= 0) {
// Make file-loader ignore WASM files
oneOf.exclude.push(wasmExtensionRegExp);
}
});
});
// Add a dedicated loader for WASM
config.module.rules.push({
test: wasmExtensionRegExp,
include: path.resolve(__dirname, "src"),
use: [{ loader: require.resolve("wasm-loader"), options: {} }],
});
config.optimization.splitChunks.minSize = 500000;
config.optimization.splitChunks.maxSize = 1000000;
return config;
};