-
Notifications
You must be signed in to change notification settings - Fork 3
/
next.config.js
70 lines (62 loc) · 2.01 KB
/
next.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
70
/** @type {import('next').NextConfig} */
const path = require('path'); //added
const nextConfig = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true
},
reactStrictMode: true,
swcMinify: true,
images: {
domains: ['i.ibb.co', 'raw.githubusercontent.com'] // Added 'raw.githubusercontent.com'
},
// added below code
// future: { webpack5: true },
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
const wasmExtensionRegExp = /\.wasm$/;
config.experiments = {
asyncWebAssembly: true,
layers: true
};
if (!dev && isServer) {
config.output.webassemblyModuleFilename = 'chunks/[id].wasm';
config.plugins.push(new WasmChunksFixPlugin());
}
config.resolve.extensions.push('.wasm');
config.module.rules.forEach((rule) => {
(rule.oneOf || []).forEach((oneOf) => {
if (oneOf.loader && oneOf.loader.indexOf('file-loader') >= 0) {
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: {} }]
});
if (!isServer) {
config.resolve.fallback.fs = false;
}
return config;
}
};
module.exports = nextConfig;
// added
class WasmChunksFixPlugin {
apply(compiler) {
compiler.hooks.thisCompilation.tap('WasmChunksFixPlugin', (compilation) => {
compilation.hooks.processAssets.tap({ name: 'WasmChunksFixPlugin' }, (assets) =>
Object.entries(assets).forEach(([pathname, source]) => {
if (!pathname.match(/\.wasm$/)) return;
compilation.deleteAsset(pathname);
const name = pathname.split('/')[1];
const info = compilation.assetsInfo.get(pathname);
compilation.emitAsset(name, source, info);
})
);
});
}
}