@@ -57,14 +57,19 @@ const extractTextPluginOptions = shouldUseRelativeAssetPaths
57
57
// This is the production configuration.
58
58
// It compiles slowly and is focused on producing a fast and minimal bundle.
59
59
// The development configuration is different and lives in a separate file.
60
- module . exports = {
60
+ const configure = indexName => ( {
61
+ // Name in compilation output log when multiple entry files are used.
62
+ name : `${ indexName } .html` ,
61
63
// Don't attempt to continue if there are any errors.
62
64
bail : true ,
63
65
// We generate sourcemaps in production. This is slow but gives good results.
64
66
// You can exclude the *.map files from the build during deployment.
65
67
devtool : 'source-map' ,
66
68
// In production, we only want to load the polyfills and the app code.
67
- entry : [ require . resolve ( './polyfills' ) , paths . appIndexJs ] ,
69
+ entry : [
70
+ require . resolve ( './polyfills' ) ,
71
+ paths . appIndexJs . replace ( 'index' , indexName ) ,
72
+ ] ,
68
73
output : {
69
74
// The build folder.
70
75
path : paths . appBuild ,
@@ -258,6 +263,7 @@ module.exports = {
258
263
new InterpolateHtmlPlugin ( env . raw ) ,
259
264
// Generates an `index.html` file with the <script> injected.
260
265
new HtmlWebpackPlugin ( {
266
+ filename : `${ indexName } .html` ,
261
267
inject : true ,
262
268
template : paths . appHtml ,
263
269
minify : {
@@ -301,7 +307,9 @@ module.exports = {
301
307
// to their corresponding output file so that tools can pick it up without
302
308
// having to parse `index.html`.
303
309
new ManifestPlugin ( {
304
- fileName : 'asset-manifest.json' ,
310
+ fileName : indexName === 'index'
311
+ ? 'asset-manifest.json'
312
+ : `${ indexName } -asset-manifest.json` ,
305
313
} ) ,
306
314
// Generate a service worker script that will precache, and keep up to date,
307
315
// the HTML & assets that are part of the Webpack build.
@@ -311,7 +319,9 @@ module.exports = {
311
319
// If a URL is already hashed by Webpack, then there is no concern
312
320
// about it being stale, and the cache-busting can be skipped.
313
321
dontCacheBustUrlsMatching : / \. \w { 8 } \. / ,
314
- filename : 'service-worker.js' ,
322
+ fileName : indexName === 'index'
323
+ ? 'service-worker.js'
324
+ : `${ indexName } -service-worker.js` ,
315
325
logger ( message ) {
316
326
if ( message . indexOf ( 'Total precache size is' ) === 0 ) {
317
327
// This message occurs for every build and is a bit too noisy.
@@ -321,7 +331,7 @@ module.exports = {
321
331
} ,
322
332
minify : true ,
323
333
// For unknown URLs, fallback to the index page
324
- navigateFallback : publicUrl + '/index .html' ,
334
+ navigateFallback : ` ${ publicUrl } / ${ indexName } .html` ,
325
335
// Ignores URLs starting from /__ (useful for Firebase):
326
336
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
327
337
navigateFallbackWhitelist : [ / ^ (? ! \/ _ _ ) .* / ] ,
@@ -345,4 +355,16 @@ module.exports = {
345
355
net : 'empty' ,
346
356
tls : 'empty' ,
347
357
} ,
348
- } ;
358
+ } ) ;
359
+
360
+ // Read potential indexXX.js candidates from src/ at this point.
361
+ const fs = require ( 'fs' ) ;
362
+ const indexFiles = fs . readdirSync ( paths . appSrc ) . filter ( file => {
363
+ // Takes all indexXX.js files. Does not check validity at this point, could be a directory and crash.
364
+ return path . basename ( file ) . startsWith ( 'index' ) &&
365
+ path . extname ( file ) === '.js' ;
366
+ } ) ;
367
+
368
+ // Returns an array of configurations to trigger webpack multicompilation
369
+ module . exports = indexFiles . map ( indexFile =>
370
+ configure ( path . parse ( indexFile ) . name ) ) ;
0 commit comments