cross platform “rm” command

The npm package rimraf is available for command-line usage in scripts.

First install locally into your project:

$ npm install --save-dev rimraf

Then update the build script in your package.json file:

"scripts": {
   "prebuild": "rimraf --glob 'bundles/*.js'",
   "build": "webpack"
}

The rimraf command (named after rm -rf) deletes the files.

Documentation:
https://www.npmjs.com/package/rimraf#cli

rimraf is a well established project with over 3,000 4,000 5,000 ⭐s on GitHub.

2023-03-04 Update:
Added the --glob flag (introduced in rimraf v4.2), and single quoted the path parameter so the glob is interpreted by rimraf instead of the shell (important for cross-platform consistency).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)