This repository was archived by the owner on Oct 30, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,25 @@ const formatUrl = (url: string) =>
46
46
const printLink = ( type : 'style' | 'script' ) => ( link : string ) =>
47
47
` Link: </${ link } >; rel=preload; as=${ type } `
48
48
49
+ const printRedirectsLine = ( [ url , path ] : [ string , string ] ) => {
50
+ const input = formatUrl ( url )
51
+ const output = '/'
52
+ if ( input === output ) return
53
+ return `${ input } ${ output } 200`
54
+ }
55
+
56
+ const redirectsTemplate = ( {
57
+ routes,
58
+ bundle,
59
+ } : {
60
+ routes : Routes
61
+ bundle : OutputBundle
62
+ } ) =>
63
+ Object . entries ( routes )
64
+ . map ( printRedirectsLine )
65
+ . filter ( ( r ) : r is string => r !== undefined )
66
+ . join ( '\n' )
67
+
49
68
const headersTemplate = ( {
50
69
routes,
51
70
entryStyles,
@@ -124,6 +143,7 @@ in the options for the html plugin`,
124
143
}
125
144
const htmlPath = join ( outputDir , 'index.html' )
126
145
const headersPath = join ( outputDir , '_headers' )
146
+ const redirectsPath = join ( outputDir , '_redirects' )
127
147
if ( ! ( await exists ( outputDir ) ) ) {
128
148
await mkdir ( outputDir )
129
149
}
@@ -138,6 +158,13 @@ in the options for the html plugin`,
138
158
bundle,
139
159
} ) ,
140
160
) ,
161
+ writeFile (
162
+ redirectsPath ,
163
+ redirectsTemplate ( {
164
+ routes,
165
+ bundle,
166
+ } ) ,
167
+ ) ,
141
168
] )
142
169
} ,
143
170
}
You can’t perform that action at this time.
0 commit comments