forked from DFXswiss/services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
55 lines (52 loc) · 1.75 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
const path = require('path');
const webpack = require('webpack');
const version = require('./package.json').version;
const widgetVersion = version.split('.').slice(0, 2).join('.');
module.exports = function override(config, env) {
config.resolve.fallback = {
...config.resolve.fallback,
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
url: require.resolve('url/'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
'process/browser': require.resolve('process/browser'),
};
config.resolve.extensions = [...config.resolve.extensions, '.ts', '.js'];
config.plugins = [
...config.plugins,
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
];
config.output = {
...config.output,
...(process.env.PUBLIC_URL && process.env.CUSTOM_CHUNK_PATH
? {
publicPath: process.env.PUBLIC_URL + process.env.CUSTOM_CHUNK_PATH,
chunkFilename: config.output.chunkFilename.replace('static/js', `v${widgetVersion}-chunks`),
webassemblyModuleFilename: `v${widgetVersion}-chunks/[hash].module.wasm`,
}
: undefined),
};
// add support for WASM
const wasmExtensionRegExp = /\.wasm$/;
config.resolve.extensions.push('.wasm');
config.module.rules.forEach((rule) => {
(rule.oneOf || []).forEach((oneOf) => {
if (oneOf.type === 'asset/resource') {
oneOf.exclude.push(wasmExtensionRegExp);
}
});
});
config.module.rules.push({
test: wasmExtensionRegExp,
include: path.resolve(__dirname, 'src'),
use: [{ loader: require.resolve('wasm-loader'), options: {} }],
});
config.experiments = {
asyncWebAssembly: true,
};
return config;
};