generated from huangmh/client_iot-daoshi-template-v
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
772 B
34 lines
772 B
const path = require('path')
|
|
const prod = process.env.NODE_ENV === 'production'
|
|
const fs = require('fs')
|
|
|
|
class DelPlugin {
|
|
apply(compiler) {
|
|
compiler.hooks.done.tap('DelPlugin', () => {
|
|
prod && deleteFolderRecursive(path.resolve(__dirname, '../../dist/static/offline'))
|
|
})
|
|
}
|
|
}
|
|
|
|
function deleteFolderRecursive(url) {
|
|
let files = []
|
|
|
|
if (fs.existsSync(url)) {
|
|
files = fs.readdirSync(url)
|
|
files.forEach(file => {
|
|
const curPath = path.join(url, file)
|
|
|
|
if (fs.statSync(curPath).isDirectory()) {
|
|
deleteFolderRecursive(curPath)
|
|
} else {
|
|
fs.unlinkSync(curPath)
|
|
}
|
|
})
|
|
|
|
fs.rmdirSync(url)
|
|
} else {
|
|
console.log('给定的路径不存在,请给出正确的路径')
|
|
}
|
|
}
|
|
|
|
module.exports = DelPlugin
|
|
|