Background
When using Vue.js in the frontend, it’s necessary to package the dist folder via npm run build, which is then placed on the server for user access.
Every time the frontend version is updated, a re-packaging is required. By default, the output folder is named dist, so I wrote a script to automatically delete the old dist folder; otherwise, an error like dist already exists would be prompted.
Previous colleagues used Windows, so the script in package.json was written as:
"scripts": {
"clean": "if exist dist rmdir /s /q dist && if exist dist.zip del dist.zip",
...
}
My machine runs macOS, so executing this script caused errors. Later, I discovered a Node.js package called rimraf that specifically solves this issue by providing cross-platform support equivalent to Linux’s rm -rf command. It’s very simple to use: after installing rimraf, just update the script to:
"scripts": {
"clean": "rimraf dist dist.zip",
...
}
Problem solved ![]()