forked from rescript-association/rescript-lang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
88 lines (81 loc) · 2.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const { ProvidePlugin } = require('webpack');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
const bsconfig = require("./bsconfig.json");
const path = require("path");
const remarkSlug = require("remark-slug");
const fs = require("fs");
const transpileModules = ["rescript"].concat(bsconfig["bs-dependencies"]);
const withTM = require("next-transpile-modules")(transpileModules);
const withMdx = require("./plugins/next-mdx")({
extension: /\.mdx?$/,
options: {
remarkPlugins: [remarkSlug],
},
});
// esbuild-loader specific features
// See: https://github.com/privatenumber/esbuild-loader-examples/blob/master/examples/next/next.config.js
function useEsbuildMinify(config, options) {
const terserIndex = config.optimization.minimizer.findIndex(minimizer => (minimizer.constructor.name === 'TerserPlugin'));
if (terserIndex > -1) {
config.optimization.minimizer.splice(
terserIndex,
1,
new ESBuildMinifyPlugin(options),
);
}
}
const isWebpack5 = true;
const config = {
target: "serverless",
pageExtensions: ["jsx", "js", "bs.js", "mdx", "mjs"],
env: {
ENV: process.env.NODE_ENV,
},
webpack: (config, options) => {
const { isServer } = options;
if (isWebpack5) {
if (!isServer) {
// We shim fs for things like the blog slugs component
// where we need fs access in the server-side part
config.resolve.fallback = {
fs: false,
path: false,
};
}
useEsbuildMinify(config);
// We need this additional rule to make sure that mjs files are
// correctly detected within our src/ folder
config.module.rules.push({
test: /\.m?js$/,
// v-- currently using an experimental setting with esbuild-loader
//use: options.defaultLoaders.babel,
use: [{loader: 'esbuild-loader', options: { loader: 'jsx'}}],
exclude: /node_modules/,
type: "javascript/auto",
resolve: {
fullySpecified: false,
}
});
config.plugins.push(new ProvidePlugin({ React: "react" }));
}
return config;
},
async redirects() {
return [
{
source: "/community",
destination: "/community/overview",
permanent: true,
},
{
source: "/bucklescript-rebranding",
destination: "/blog/bucklescript-is-rebranding",
permanent: true,
},
];
},
future: {
webpack5: isWebpack5,
},
};
module.exports = withMdx(withTM(config));