Ignoring & Copying Files
You want to ignore your test files:
"scripts": {
"prebuild": "rimraf dist",
// **** 1. add ignore ↴
"build": "babel --copy-files --out-dir dist --ignore *.test.js src",
"test": "nyc mocha",
"watch:test": "mocha --watch",
"lint": "eslint src",
// **** 2. also added build to the end ↴
"validate": "npm-run-all --parallel test lint build"
},
###Add an npm srcipt to clean the directory before the build is run
You can add the pre
prefix to a srcipt and it will run it before.
"prebuild": "rimraf dist",
He uses rimraf
package, that is cross-platform (Windows) for cleaning the dir.
npm i -D rimraf
what about the
watch:test
script name?
It's fairly conventional, like npm-run-all
uses it too. We will use this later when building for browser and commonjs.
We now have a problem that the index.js file we transpiled, looks for the (requires) the json file from the same directory. Since the json file is not transpiled, it's not in the dist
directory.
He likes that it's only the dist directory that he sends to npm, so it should contain everything.
He will use Babel to copy all non .js files:
"build": "babel --copy-files --out-dir dist --ignore *.test.js src",
Notice the --copy-files
.
finally adds the build
at the end of validate
:
"validate": "npm-run-all --parallel test lint build"
They can run in parallel no problem.