@@ -7,7 +7,7 @@ import flatMap from 'lodash/flatMap'
77import React from 'react'
88import { invariant , getRequiredChunkKey } from './sharedInternals'
99import ChunkExtractorManager from './ChunkExtractorManager'
10- import { smartRequire , joinURLPath } from './util'
10+ import { smartRequire , joinURLPath , readJsonFileSync } from './util'
1111
1212const EXTENSION_SCRIPT_TYPES = {
1313 '.js' : 'script' ,
@@ -205,7 +205,7 @@ class ChunkExtractor {
205205 inputFileSystem = fs ,
206206 } = { } ) {
207207 this . namespace = namespace
208- this . stats = stats || smartRequire ( statsFile )
208+ this . stats = stats || readJsonFileSync ( inputFileSystem , statsFile )
209209 this . publicPath = publicPath || this . stats . publicPath
210210 this . outputPath = outputPath || this . stats . outputPath
211211 this . statsFile = statsFile
@@ -383,18 +383,30 @@ class ChunkExtractor {
383383 // Utilities
384384
385385 requireEntrypoint ( entrypoint ) {
386+ const entrypointPath = this . getEntrypointPath ( this . entrypoint )
387+
388+ this . getAllScriptAssetsPaths ( )
389+ . forEach ( ( assetPath ) => {
390+ smartRequire ( assetPath )
391+ } )
392+
393+ return smartRequire ( entrypointPath )
394+ }
395+
396+ getEntrypointPath ( entrypoint ) {
386397 entrypoint = entrypoint || this . entrypoints [ 0 ]
387398 const assets = this . getChunkAssets ( entrypoint )
388399 const mainAsset = assets . find ( asset => asset . scriptType === 'script' )
389400 invariant ( mainAsset , 'asset not found' )
401+ return cleanFileName ( mainAsset . path )
402+ }
390403
391- this . stats . assets
404+ getAllScriptAssetsPaths ( ) {
405+ return this . stats . assets
392406 . filter ( ( { name } ) => isScriptFile ( name ) )
393- . forEach ( ( { name } ) => {
394- smartRequire ( path . join ( this . outputPath , cleanFileName ( name ) ) )
407+ . map ( ( { name } ) => {
408+ return path . join ( this . outputPath , cleanFileName ( name ) )
395409 } )
396-
397- return smartRequire ( cleanFileName ( mainAsset . path ) )
398410 }
399411
400412 // Main assets
0 commit comments