NPM packages can declare named commands in the "scripts"
section of their
package.json
. NPM scripts are a useful way to run repetitive tasks necessary
for maintaining the package.
As an example, the ember.js package.json
declares
a start
script to run a local web server,
a test
script to run the package’s test suite, and
a build
script to transpile, concatenate, and minify the package.
To execute the start
script, run:
$ npm start
To execute the test
script, run:
$ npm test
This will execute the pretest
script before the test
script.
To execute the build
script, you would probably expect to run:
$ npm build # womp womp
This will not behave like start
or test
.
NPM only supports a specific set of scripts and hooks, and build
is
not directly supported.
To execute the build
script, run:
$ npm run-script build
It is also important to note that a prebuild
hook would not fire before the
build
script’s execution.