@@ -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 . baseUrl , 'index.html' ) }
144
- ]
141
+ rewrites : genHistoryApiFallbackRewrites ( options . baseUrl , options . pages )
145
142
} ,
146
143
contentBase : api . resolve ( 'public' ) ,
147
144
watchContentBase : ! isProduction ,
@@ -302,6 +299,20 @@ 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
+ . map ( name => ( {
307
+ from : new RegExp ( `^/${ name } ` ) ,
308
+ to : path . posix . join ( baseUrl , pages [ name ] . filename || `${ name } .html` )
309
+ } ) )
310
+ return [
311
+ ...multiPageRewrites ,
312
+ { from : / ./ , to : path . posix . join ( baseUrl , 'index.html' ) }
313
+ ]
314
+ }
315
+
305
316
module . exports . defaultModes = {
306
317
serve : 'development'
307
318
}
0 commit comments