1
- // @ts -check
2
- import fs from "fs" ;
1
+ // @ ts-check
2
+
3
+ import * as assert from "node:assert/strict" ;
4
+ import * as path from "node:path" ;
5
+ import * as fs from "node:fs/promises" ;
3
6
import webpack from "webpack" ;
4
7
import rehypeSlug from "rehype-slug" ;
5
8
import remarkGfm from "remark-gfm" ;
@@ -8,14 +11,15 @@ import remarkFrontmatter from "remark-frontmatter";
8
11
import remarkMdxFrontmatter from "remark-mdx-frontmatter" ;
9
12
import { createLoader } from "simple-functional-loader" ;
10
13
11
- const bsconfig = JSON . parse ( fs . readFileSync ( "./rescript.json" ) . toString ( ) ) ;
14
+ const bsconfig = JSON . parse ( ( await fs . readFile ( "./rescript.json" , "utf8" ) ) . toString ( ) ) ;
12
15
13
16
const { ProvidePlugin } = webpack ;
14
17
15
18
const transpileModules = [ "rescript" ] . concat ( bsconfig [ "bs-dependencies" ] ) ;
16
19
20
+ /** @type {import("next").NextConfig } */
17
21
const config = {
18
- output : " export",
22
+ output : process . env . NODE_ENV === "production" ? " export" : undefined ,
19
23
pageExtensions : [ "jsx" , "js" , "bs.js" , "mdx" , "mjs" ] ,
20
24
env : {
21
25
ENV : process . env . NODE_ENV ,
@@ -84,6 +88,94 @@ const config = {
84
88
config . plugins . push ( new ProvidePlugin ( { React : "react" } ) ) ;
85
89
return config ;
86
90
} ,
91
+ async redirects ( ) {
92
+ const redirects = [
93
+ {
94
+ source : "/community" ,
95
+ destination : "/community/overview" ,
96
+ permanent : true ,
97
+ } ,
98
+ {
99
+ source : "/bucklescript-rebranding" ,
100
+ destination : "/blog/bucklescript-is-rebranding" ,
101
+ permanent : true ,
102
+ } ,
103
+ {
104
+ source : "/docs/manual/latest/migrate-from-bucklescript-reason" ,
105
+ destination : "/docs/manual/v10.0.0/migrate-from-bucklescript-reason" ,
106
+ permanent : true ,
107
+ } ,
108
+ {
109
+ source : "/docs/manual/latest/unboxed" ,
110
+ destination : "/docs/manual/v10.0.0/unboxed" ,
111
+ permanent : true ,
112
+ } ,
113
+ {
114
+ source : "/docs/gentype/latest/introduction" ,
115
+ destination : "/docs/manual/latest/typescript-integration" ,
116
+ permanent : true ,
117
+ } ,
118
+ {
119
+ source : "/docs/gentype/latest/getting-started" ,
120
+ destination : "/docs/manual/latest/typescript-integration" ,
121
+ permanent : true ,
122
+ } ,
123
+ {
124
+ source : "/docs/gentype/latest/usage" ,
125
+ destination : "/docs/manual/latest/typescript-integration" ,
126
+ permanent : true ,
127
+ } ,
128
+ {
129
+ source : "/docs/gentype/latest/supported-types" ,
130
+ destination : "/docs/manual/latest/typescript-integration" ,
131
+ permanent : true ,
132
+ } ,
133
+ ] ;
134
+ const splatRedirects = [
135
+ {
136
+ source : "/docs/manual/latest/:slug*" ,
137
+ destination : `/docs/manual/${ process . env . VERSION_LATEST } /:slug*` ,
138
+ permanent : false ,
139
+ } ,
140
+ {
141
+ source : "/docs/manual/next/:slug*" ,
142
+ destination : `/docs/manual/${ process . env . VERSION_NEXT } /:slug*` ,
143
+ permanent : false ,
144
+ } ,
145
+ {
146
+ source : "/llms/manual/latest/:file*" ,
147
+ destination : `/llms/manual/${ process . env . VERSION_LATEST } /:file*` ,
148
+ permanent : false ,
149
+ } ,
150
+ {
151
+ source : "/llms/manual/next/:file*" ,
152
+ destination : `/llms/manual/${ process . env . VERSION_NEXT } /:file*` ,
153
+ permanent : false ,
154
+ } ,
155
+ ] ;
156
+
157
+ const redirectsFile = path . join ( import . meta. dirname , "public/_redirects" ) ;
158
+ await fs . writeFile (
159
+ redirectsFile ,
160
+ redirects
161
+ . map ( ( { source, destination, permanent } ) => {
162
+ return `${ source } ${ destination } ${ permanent ? 308 : 307 } ` ;
163
+ } )
164
+ . join ( "\n" ) +
165
+ "\n" +
166
+ splatRedirects
167
+ . map ( ( { source, destination, permanent } ) => {
168
+ const splatPattern = / : ( \w + ) \* $ / ;
169
+ assert . match ( source , splatPattern ) ;
170
+ assert . match ( destination , splatPattern ) ;
171
+ return `${ source . replace ( splatPattern , "*" ) } ${ destination . replace ( splatPattern , ":splat" ) } ${ permanent ? 308 : 307 } ` ;
172
+ } )
173
+ . join ( "\n" ) ,
174
+ "utf8" ,
175
+ ) ;
176
+
177
+ return [ ...redirects , ...splatRedirects ] ;
178
+ } ,
87
179
} ;
88
180
89
181
export default {
0 commit comments