I currently have the following script in my package.json for deleting all ".js" files in my bundles folder for when I run "npm run build". It works fine when running it in dev servers but breaks when it is run in a Windows machine.
{ "scripts": { "build": "rm bundles/*.js && webpack", }, }
Since I am hashing all my build files, I am required to delete them all before adding new ones, such that I don't end up with a bunch of old builds.
Is there a "rm bundles/*.js" that would work in both Mac and Windows?
So yes, you can use the 'rm' command on windows.
The goal of cross-var is to let you use one script syntax to work either on a Mac OS X/Linux (bash) or Windows. Reference the Usage documention below on how to use cross-var in your scripts.
You can get npx now by installing [email protected] or later — or, if you don't want to use npm, you can install the standalone version of npx! It's totally compatible with other package managers, since any npm usage is only done for internal operations.
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 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 ⭐s on GitHub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With