-
Notifications
You must be signed in to change notification settings - Fork 2
/
next.config.js
43 lines (40 loc) · 1.38 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
const { join } = require("path");
const { symlink, access, mkdir } = require("fs/promises");
const basePath = (process.env.NEXT_PUBLIC_BASE_PATH || "").replace("http://", "https://");
const assetPrefix = (process.env.NEXT_PUBLIC_ASSET_PATH || "").replace("http://", "https://");
const nextConfig = {
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
basePath,
assetPrefix,
// experimental: {
// mdxRs: true,
// },
output: "export",
webpack: (config, { isServer, dev }) => {
config.experiments = Object.assign(config.experiments || {}, {
asyncWebAssembly: true,
layers: true,
});
if (!dev && isServer) {
config.output.webassemblyModuleFilename = "chunks/[id].wasm";
config.plugins.push(new WasmChunksFixPlugin());
}
return config;
},
};
module.exports = nextConfig;
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);
}),
);
});
}
}