The file package.json
:
All Node projects that use any package manager, such as NPM or Yarn have a package.json
file, which defines the overall metrics of the project, identifying the dependencies, package name, and many other information.
To learn more about the package.json
file and all its features, please refer to package.json
a>.
The npm scripts :
One of the features that package managers like NPM or Yarn provide are scripts , which basically consist of " shortcuts" for commands, defined in the file package.json
. They also provide hooks for the package life cycle.
An example (file package.json
):
{
"scripts": {
"start": "node app.js"
}
}
Note that above we have defined the script start
, which can be invoked by your terminal using npm run start
, or, in its reduced form npm start
.
The command npm build
:
As demonstrated above, the author of a package can define custom scripts for your package. Now imagine that this package needs a build step. This need is very common in projects that use features like TypeScript .
An example:
Because the package can not be published to the NPM record with TypeScript code, it is very common to create a script (usually by convention, with the name build
), to do build
of the TypeScript code for JavaScript:
{
"scripts": {
"build": "tsc" <-- Comando usado para compilar arquivos TypeScript em JS!
}
}
This was only one of the examples for npm build
, since its use varies according to the project.
Extra reading