Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why to use "rimraf dist" command in build script

What is the reason for running "rimraf dist" command in the build script in package.json file?

"scripts": {
    "build": "rimraf dist ..."
  },
like image 357
Tal Avatar asked Apr 21 '19 19:04

Tal


2 Answers

The rimraf package which you will probably find in the devDependencies section of the package.json you have, is used to safely remove files and folders on all platforms (Unix and Windows).

When you have a build system, you want to also make sure you remove the output files before re-emitting the build output content (especially in case you have removed some files which are not needed anymore). You could go ahead and do:

"scripts": {
  "clean": "rm ./dist/* -Recurse -Force"
}

But that will work on Windows only, and sometimes will also give you problems due to issues around the use of *. On Unix the command would be different. In order to make things better, rimraf does the removal for you so you can simply invoke it in your scripts/clean section:

"scripts": {
  "clean": "rimraf dist"
}

This will ensure your package.json (your build system) to be cross-platform.

like image 117
Andry Avatar answered Sep 23 '22 14:09

Andry


rimraf
A rm -rf util for nodejs

$ rimraf dist removes the dist file or folder.
I guess the build script puts stuff inside the dist directory and wants to remove the old stuff from the last time you build it.

like image 23
0xnoob Avatar answered Sep 23 '22 14:09

0xnoob