11module . exports = async function build ( sourceDir , cliOptions = { } ) {
22 process . env . NODE_ENV = 'production'
33
4- const fs = require ( 'fs' )
4+ const fs = require ( 'fs-extra ' )
55 const path = require ( 'path' )
66 const chalk = require ( 'chalk' )
77 const webpack = require ( 'webpack' )
88 const readline = require ( 'readline' )
9- const { promisify } = require ( 'util' )
109 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 )
1510
1611 const prepare = require ( './prepare' )
1712 const createClientConfig = require ( './webpack/createClientConfig' )
@@ -26,7 +21,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
2621 }
2722
2823 const { outDir } = options
29- await rimraf ( outDir )
24+ await fs . remove ( outDir )
3025
3126 let clientConfig = createClientConfig ( options , cliOptions ) . toConfig ( )
3227 let serverConfig = createServerConfig ( options , cliOptions ) . toConfig ( )
@@ -48,7 +43,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
4843 const clientManifest = require ( path . resolve ( outDir , 'manifest/client.json' ) )
4944
5045 // remove manifests after loading them.
51- await rimraf ( path . resolve ( outDir , 'manifest' ) )
46+ await fs . remove ( path . resolve ( outDir , 'manifest' ) )
5247
5348 // find and remove empty style chunk caused by
5449 // https://github.com/webpack-contrib/mini-css-extract-plugin/issues/85
@@ -60,7 +55,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
6055 clientManifest,
6156 runInNewContext : false ,
6257 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' )
6459 } )
6560
6661 // pre-render head tags from user config
@@ -154,8 +149,8 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
154149 }
155150 const filename = pagePath . replace ( / \/ $ / , '/index.html' ) . replace ( / ^ \/ / , '' )
156151 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 )
159154 }
160155
161156 function renderPageMeta ( meta ) {
@@ -174,15 +169,15 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
174169 return / s t y l e s \. \w { 8 } \. j s $ / . test ( a . name )
175170 } )
176171 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 )
179174 // prepend it to app.js.
180175 // this is necessary for the webpack runtime to work properly.
181176 const appChunk = stats . children [ 0 ] . assets . find ( a => {
182177 return / a p p \. \w { 8 } \. j s $ / . test ( a . name )
183178 } )
184179 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 )
187182 }
188183}
0 commit comments