@@ -8,6 +8,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
8
8
const { promisify } = require ( 'util' )
9
9
const rimraf = promisify ( require ( 'rimraf' ) )
10
10
const mkdirp = promisify ( require ( 'mkdirp' ) )
11
+ const readFile = promisify ( fs . readFile )
11
12
const writeFile = promisify ( fs . writeFile )
12
13
13
14
const prepare = require ( './prepare' )
@@ -27,14 +28,18 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
27
28
const serverConfig = createServerConfig ( options , cliOptions ) . toConfig ( )
28
29
29
30
// compile!
30
- await compile ( [ clientConfig , serverConfig ] )
31
+ const stats = await compile ( [ clientConfig , serverConfig ] )
31
32
32
33
const serverBundle = require ( path . resolve ( outDir , 'manifest/server.json' ) )
33
34
const clientManifest = require ( path . resolve ( outDir , 'manifest/client.json' ) )
34
35
35
36
// remove manifests after loading them.
36
37
await rimraf ( path . resolve ( outDir , 'manifest' ) )
37
38
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
+
38
43
// create server renderer using built manifests
39
44
const renderer = createBundleRenderer ( serverBundle , {
40
45
clientManifest,
@@ -76,7 +81,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
76
81
reject ( new Error ( `Failed to compile with errors.` ) )
77
82
return
78
83
}
79
- resolve ( )
84
+ resolve ( stats . toJson ( { modules : false } ) )
80
85
} )
81
86
} )
82
87
}
@@ -121,4 +126,21 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
121
126
await mkdirp ( path . dirname ( filePath ) )
122
127
await writeFile ( filePath , html )
123
128
}
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
+ }
124
146
}
0 commit comments