-
Notifications
You must be signed in to change notification settings - Fork 5
/
craco.config.js
69 lines (59 loc) · 2.27 KB
/
craco.config.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
65
66
67
68
69
const path = require('path');
const WasmPackPlugin = require('@wasm-tool/wasm-pack-plugin');
const wasmPlugin = {
plugin: {
overrideWebpackConfig: ({webpackConfig}) => {
const wasmExtensionRegExp = /\.wasm$/;
// derived from here
// https://tomtongue.com/blog/2019/03/07/react-rust-wasm.html
// Make file-loader ignore WASM files
webpackConfig.module.rules.forEach((rule) => {
(rule.oneOf || []).forEach((oneOf) => {
if (oneOf.loader && oneOf.loader.indexOf('file-loader') >= 0) {
// Make file-loader ignore WASM files
oneOf.exclude.push(wasmExtensionRegExp);
}
});
});
webpackConfig.plugins.push(
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, './wasm'),
// Check https://rustwasm.github.io/wasm-pack/book/commands/build.html for
// the available set of arguments.
//
// Default arguments are `--typescript --target browser --mode normal`.
// extraArgs: '--no-typescript',
withTypeScript: true,
// Optional array of absolute paths to directories, changes to which
// will trigger the build.
// watchDirectories: [
// path.resolve(__dirname, "another-crate/src")
// ],
// The same as the `--out-dir` option for `wasm-pack`
outDir: path.resolve(__dirname, './src/pkg'),
// The same as the `--out-name` option for `wasm-pack`
// outName: "index",
// If defined, `forceWatch` will force activate/deactivate watch mode for
// `.rs` files.
//
// The default (not set) aligns watch mode for `.rs` files to Webpack's
// watch mode.
// forceWatch: true,
// If defined, `forceMode` will force the compilation mode for `wasm-pack`
//
// Possible values are `development` and `production`.
//
// the mode `development` makes `wasm-pack` build in `debug` mode.
// the mode `production` makes `wasm-pack` build in `release` mode.
// forceMode: "development",
}),
);
return webpackConfig;
},
},
};
module.exports = function ({ env }) {
return {
plugins: [wasmPlugin],
};
};