例:
- 某个node文件,定义了一个删除文件方法delFile:
const path = require('path');
function delFile(filePath){
let _path = path.resolve(__dirname, filePath);
fs.unlink(_path, err => {
if(err){
console.log('文件删除失败!')
throw err;
}
console.log('删除成功!')
})
}
module.exports={
delFile
}
- package.json中编写调用脚本:
"start": "node ./config/start.js",
"rm": "node -e \"require('./config/file').delFile('../dist.zip')\""
}
注意:多层引号时,需增加\"作为标识。
- 执行package.json中的rm脚本:
npm run rm