I'm working on a project in Node.js and using babel to transpile my code. My package.json
has a build
command defined like this:
"scripts": {
"build": "yarn run babel src -d lib",
},
This transpiles fine, taking the content of src
and outputing the result to lib
, but there are two issues:
lib
will contain old files from past transpiles even if they no longer have a matching file in src
.src/Foo.js
and later renamed it to src/foo.js
then future transpiles will still be named lib/Foo.js
Can I tell babel to wipe away the contents of the lib
directory before transpiling or do I need to just insert a rm
into the build script?
Babel does not have functionality to do this. It is very common to use a rimraf
or some other means to delete the directory before running Babel. rm
directly is certainly also an option, but that does get more complicated if you want to support Windows too, hence the rimraf
usage.