-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
next.config.mjs
133 lines (124 loc) · 3.68 KB
/
next.config.mjs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import fs from "fs";
import webpack from "webpack";
import rehypeSlug from "rehype-slug";
import remarkGfm from "remark-gfm";
import remarkComment from "remark-comment";
import remarkFrontmatter from "remark-frontmatter";
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
import { createLoader } from "simple-functional-loader";
const bsconfig = JSON.parse(fs.readFileSync("./rescript.json"));
const { ProvidePlugin } = webpack;
const transpileModules = ["rescript"].concat(bsconfig["bs-dependencies"]);
const config = {
output: process.env.BUILD_STATIC === 'true' ? 'export' : undefined,
pageExtensions: ["jsx", "js", "bs.js", "mdx", "mjs"],
env: {
ENV: process.env.NODE_ENV,
},
swcMinify: false,
webpack: (config, options) => {
const { isServer } = options;
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,
};
}
// 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,
},
});
function mainMdxLoader(plugins) {
return [
createLoader(function(source) {
const result = `${source}\n\nMDXContent.frontmatter = frontmatter`;
return result;
}),
];
}
config.module.rules.push({
test: /\.mdx?$/,
use: mainMdxLoader(),
});
config.module.rules.push({
test: /\.mdx?$/,
use: [
{
loader: "@mdx-js/loader",
/** @type {import('@mdx-js/loader').Options} */
options: {
remarkPlugins: [
remarkComment,
remarkGfm,
remarkFrontmatter,
remarkMdxFrontmatter,
],
providerImportSource: "@mdx-js/react",
rehypePlugins: [rehypeSlug],
},
},
],
});
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,
},
{
source: "/docs/manual/latest/migrate-from-bucklescript-reason",
destination: "/docs/manual/v10.0.0/migrate-from-bucklescript-reason",
permanent: true,
},
{
source: "/docs/manual/latest/unboxed",
destination: "/docs/manual/v10.0.0/unboxed",
permanent: true,
},
{
source: "/docs/gentype/latest/introduction",
destination: "/docs/manual/latest/typescript-integration",
permanent: true,
},
{
source: "/docs/gentype/latest/getting-started",
destination: "/docs/manual/latest/typescript-integration",
permanent: true,
},
{
source: "/docs/gentype/latest/usage",
destination: "/docs/manual/latest/typescript-integration",
permanent: true,
},
{
source: "/docs/gentype/latest/supported-types",
destination: "/docs/manual/latest/typescript-integration",
permanent: true,
},
];
},
};
export default {
transpilePackages: transpileModules,
...config,
};