@@ -33,7 +33,6 @@ module.exports = (api, options) => {
33
33
const isProduction = process . env . NODE_ENV === 'production'
34
34
35
35
const url = require ( 'url' )
36
- const path = require ( 'path' )
37
36
const chalk = require ( 'chalk' )
38
37
const webpack = require ( 'webpack' )
39
38
const WebpackDevServer = require ( 'webpack-dev-server' )
@@ -139,9 +138,7 @@ module.exports = (api, options) => {
139
138
clientLogLevel : 'none' ,
140
139
historyApiFallback : {
141
140
disableDotRule : true ,
142
- rewrites : [
143
- { from : / ./ , to : path . posix . join ( options . publicPath , 'index.html' ) }
144
- ]
141
+ rewrites : genHistoryApiFallbackRewrites ( options . publicPath , options . pages )
145
142
} ,
146
143
contentBase : api . resolve ( 'public' ) ,
147
144
watchContentBase : ! isProduction ,
@@ -302,6 +299,23 @@ function checkInContainer () {
302
299
}
303
300
}
304
301
302
+ function genHistoryApiFallbackRewrites ( baseUrl , pages = { } ) {
303
+ const path = require ( 'path' )
304
+ const multiPageRewrites = Object
305
+ . keys ( pages )
306
+ // sort by length in reversed order to avoid overrides
307
+ // eg. 'page11' should appear in front of 'page1'
308
+ . sort ( ( a , b ) => b . length - a . length )
309
+ . map ( name => ( {
310
+ from : new RegExp ( `^/${ name } ` ) ,
311
+ to : path . posix . join ( baseUrl , pages [ name ] . filename || `${ name } .html` )
312
+ } ) )
313
+ return [
314
+ ...multiPageRewrites ,
315
+ { from : / ./ , to : path . posix . join ( baseUrl , 'index.html' ) }
316
+ ]
317
+ }
318
+
305
319
module . exports . defaultModes = {
306
320
serve : 'development'
307
321
}
0 commit comments