Skip to content

Commit 7ed47d0

Browse files
committed
fix: remove old-dist when rebuild
1 parent d227cc2 commit 7ed47d0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

build/build.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@ const path = require('path')
99
const chalk = require('chalk')
1010
const webpack = require('webpack')
1111
const config = require('../config')
12+
const glob = require('glob')
13+
const fs = require('fs')
1214
const webpackConfig = require('./webpack.prod.conf')
1315

1416
const spinner = ora('building for production...')
1517
spinner.start()
18+
const TO = path.join(__dirname, '..', 'dist')
19+
20+
if(fs.existsSync(TO)){
21+
let file = []
22+
glob.sync(`${TO}/**`).forEach((pathname) => {
23+
file.push(pathname)
24+
})
25+
for(let i = file.length - 1; i >= 0; i--){
26+
if(fs.statSync( file[i] ).isFile()){
27+
fs.unlinkSync(file[i])
28+
} else {
29+
fs.rmdirSync(file[i])
30+
}
31+
}
32+
}
33+
fs.mkdirSync(TO)
1634

1735
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
1836
if (err) throw err

0 commit comments

Comments
 (0)