@@ -8,6 +8,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
88 const { promisify } = require ( 'util' )
99 const rimraf = promisify ( require ( 'rimraf' ) )
1010 const mkdirp = promisify ( require ( 'mkdirp' ) )
11+ const readFile = promisify ( fs . readFile )
1112 const writeFile = promisify ( fs . writeFile )
1213
1314 const prepare = require ( './prepare' )
@@ -27,14 +28,18 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
2728 const serverConfig = createServerConfig ( options , cliOptions ) . toConfig ( )
2829
2930 // compile!
30- await compile ( [ clientConfig , serverConfig ] )
31+ const stats = await compile ( [ clientConfig , serverConfig ] )
3132
3233 const serverBundle = require ( path . resolve ( outDir , 'manifest/server.json' ) )
3334 const clientManifest = require ( path . resolve ( outDir , 'manifest/client.json' ) )
3435
3536 // remove manifests after loading them.
3637 await rimraf ( path . resolve ( outDir , 'manifest' ) )
3738
39+ // fine and remove empty style chunk caused by
40+ // https://github.com/webpack-contrib/mini-css-extract-plugin/issues/85
41+ await workaroundEmptyStyleChunk ( )
42+
3843 // create server renderer using built manifests
3944 const renderer = createBundleRenderer ( serverBundle , {
4045 clientManifest,
@@ -76,7 +81,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
7681 reject ( new Error ( `Failed to compile with errors.` ) )
7782 return
7883 }
79- resolve ( )
84+ resolve ( stats . toJson ( { modules : false } ) )
8085 } )
8186 } )
8287 }
@@ -121,4 +126,21 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
121126 await mkdirp ( path . dirname ( filePath ) )
122127 await writeFile ( filePath , html )
123128 }
129+
130+ async function workaroundEmptyStyleChunk ( ) {
131+ const styleChunk = stats . children [ 0 ] . assets . find ( a => {
132+ return / s t y l e s \. \w { 8 } \. j s $ / . test ( a . name )
133+ } )
134+ const styleChunkPath = path . resolve ( outDir , styleChunk . name )
135+ const styleChunkContent = await readFile ( styleChunkPath , 'utf-8' )
136+ await rimraf ( styleChunkPath )
137+ // prepend it to app.js.
138+ // this is necessary for the webpack runtime to work properly.
139+ const appChunk = stats . children [ 0 ] . assets . find ( a => {
140+ return / a p p \. \w { 8 } \. j s $ / . test ( a . name )
141+ } )
142+ const appChunkPath = path . resolve ( outDir , appChunk . name )
143+ const appChunkContent = await readFile ( appChunkPath , 'utf-8' )
144+ await writeFile ( appChunkPath , styleChunkContent + appChunkContent )
145+ }
124146}
0 commit comments