Repository navigation
Expand file tree
/
Copy pathnext.config.js
More file actions
75 lines (73 loc) · 2.65 KB
/
Copy pathnext.config.js
File metadata and controls
75 lines (73 loc) · 2.65 KB
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
71
72
73
74
75
/**
* Next's minifier (SWC's compress) breaks the MLscript compiler, which is
* Scala.js output: it fails an assertion when it starts. The compiler's chunk
* is marked as minimized before Next minifies the rest, so it's left as is.
* It is only downloaded by MLscript notebooks, in their compiler worker
* (runtime/languages/mlscript.worker.js).
*/
class KeepMLscriptCompiler {
apply(compiler) {
const {Compilation} = compiler.webpack;
compiler.hooks.compilation.tap("KeepMLscriptCompiler", (compilation) => {
compilation.hooks.processAssets.tap(
{name: "KeepMLscriptCompiler", stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE - 1},
() => {
for (const chunk of compilation.chunks) {
const modules = compilation.chunkGraph.getChunkModules(chunk);
if (!modules.some((m) => /[\\/]@mlscript[\\/]recho[\\/]dist[\\/]MLscript\.mjs$/.test(m.resource ?? "")))
continue;
for (const file of chunk.files) compilation.updateAsset(file, (source) => source, {minimized: true});
}
},
);
});
}
}
/** @type {import('next').NextConfig} */
const nextConfig = {
// Example thumbnails run web-tree-sitter at build time; bundled, its
// Emscripten loader can't find Node's `module`, so Node loads it as is.
serverExternalPackages: ["web-tree-sitter"],
webpack(config, {dev, isServer}) {
if (!dev) config.plugins.push(new KeepMLscriptCompiler());
// web-tree-sitter (MLscript highlighting) imports these only under Node.
if (!isServer) config.resolve.fallback = {...config.resolve.fallback, "fs/promises": false, module: false};
// @mlscript/recho falls back to import(path) for non-std modules. We pass our own resolve
// (runtime/languages/mlscript.js), so that fallback never runs; silence webpack's warning about it.
config.ignoreWarnings = [
...(config.ignoreWarnings ?? []),
{module: /[\\/]@mlscript[\\/]recho[\\/]index\.mjs$/, message: /Critical dependency/},
];
return config;
},
async redirects() {
return [
{
source: "/notebook/:path*",
destination: "/:path*",
permanent: true,
},
{
source: "/examples",
destination: "/explore",
permanent: true,
},
{
source: "/examples/:slug",
destination: "/explore/:slug",
permanent: true,
},
{
source: "/multiples",
destination: "https://recho-multiples.vercel.app/",
permanent: true,
},
{
source: "/melody",
destination: "https://recho-melody.vercel.app/",
permanent: true,
},
];
},
};
export default nextConfig;