1
1
module . exports = async function build ( sourceDir , cliOptions = { } ) {
2
2
process . env . NODE_ENV = 'production'
3
3
4
- const fs = require ( 'fs' )
4
+ const fs = require ( 'fs-extra ' )
5
5
const path = require ( 'path' )
6
6
const chalk = require ( 'chalk' )
7
7
const webpack = require ( 'webpack' )
8
8
const readline = require ( 'readline' )
9
- const { promisify } = require ( 'util' )
10
9
const escape = require ( 'escape-html' )
11
- const rimraf = promisify ( require ( 'rimraf' ) )
12
- const mkdirp = promisify ( require ( 'mkdirp' ) )
13
- const readFile = promisify ( fs . readFile )
14
- const writeFile = promisify ( fs . writeFile )
15
10
16
11
const prepare = require ( './prepare' )
17
12
const createClientConfig = require ( './webpack/createClientConfig' )
@@ -26,7 +21,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
26
21
}
27
22
28
23
const { outDir } = options
29
- await rimraf ( outDir )
24
+ await fs . remove ( outDir )
30
25
31
26
let clientConfig = createClientConfig ( options , cliOptions ) . toConfig ( )
32
27
let serverConfig = createServerConfig ( options , cliOptions ) . toConfig ( )
@@ -48,7 +43,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
48
43
const clientManifest = require ( path . resolve ( outDir , 'manifest/client.json' ) )
49
44
50
45
// remove manifests after loading them.
51
- await rimraf ( path . resolve ( outDir , 'manifest' ) )
46
+ await fs . remove ( path . resolve ( outDir , 'manifest' ) )
52
47
53
48
// find and remove empty style chunk caused by
54
49
// https://github.com/webpack-contrib/mini-css-extract-plugin/issues/85
@@ -60,7 +55,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
60
55
clientManifest,
61
56
runInNewContext : false ,
62
57
inject : false ,
63
- template : fs . readFileSync ( path . resolve ( __dirname , 'app/index.ssr.html' ) , 'utf-8' )
58
+ template : await fs . readFile ( path . resolve ( __dirname , 'app/index.ssr.html' ) , 'utf-8' )
64
59
} )
65
60
66
61
// pre-render head tags from user config
@@ -154,8 +149,8 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
154
149
}
155
150
const filename = pagePath . replace ( / \/ $ / , '/index.html' ) . replace ( / ^ \/ / , '' )
156
151
const filePath = path . resolve ( outDir , filename )
157
- await mkdirp ( path . dirname ( filePath ) )
158
- await writeFile ( filePath , html )
152
+ await fs . ensureDir ( path . dirname ( filePath ) )
153
+ await fs . writeFile ( filePath , html )
159
154
}
160
155
161
156
function renderPageMeta ( meta ) {
@@ -174,15 +169,15 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
174
169
return / s t y l e s \. \w { 8 } \. j s $ / . test ( a . name )
175
170
} )
176
171
const styleChunkPath = path . resolve ( outDir , styleChunk . name )
177
- const styleChunkContent = await readFile ( styleChunkPath , 'utf-8' )
178
- await rimraf ( styleChunkPath )
172
+ const styleChunkContent = await fs . readFile ( styleChunkPath , 'utf-8' )
173
+ await fs . remove ( styleChunkPath )
179
174
// prepend it to app.js.
180
175
// this is necessary for the webpack runtime to work properly.
181
176
const appChunk = stats . children [ 0 ] . assets . find ( a => {
182
177
return / a p p \. \w { 8 } \. j s $ / . test ( a . name )
183
178
} )
184
179
const appChunkPath = path . resolve ( outDir , appChunk . name )
185
- const appChunkContent = await readFile ( appChunkPath , 'utf-8' )
186
- await writeFile ( appChunkPath , styleChunkContent + appChunkContent )
180
+ const appChunkContent = await fs . readFile ( appChunkPath , 'utf-8' )
181
+ await fs . writeFile ( appChunkPath , styleChunkContent + appChunkContent )
187
182
}
188
183
}
0 commit comments