Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross platform "rm" command

Tags:

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?

like image 297
jaimefps Avatar asked Jan 05 '18 20:01

jaimefps


People also ask

Does RM work on Windows?

So yes, you can use the 'rm' command on windows.

What is cross VAR?

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.

How do I get NPX?

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.


1 Answers

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.

like image 127
Dem Pilafian Avatar answered Sep 21 '22 17:09

Dem Pilafian