The archive package.json
:
All Node projects that use some package manager, such as NPM or the Yarn have a file package.json
, that defines the project metrics in general, identifying dependencies, package name, and many other information.
To learn more about the archive package.json
and all its functionalities, please refer to documentation of package.json
.
The npm scripts:
One of the features that package managers like NPM or Yarn provide is scripts, which basically consist of "shortcuts" for commands, defined in the file package.json
. They also provide Hooks for the life cycle of the package.
An example (file package.json
):
{
"scripts": {
"start": "node app.js"
}
}
Note that above we define the script start
, that 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 scripts customized for your package. Imagine now that this package needs a build. This need is very common in projects that use resources such as Typescript.
An example:
Since the package cannot 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 the build
Typescript for Javascript code:
{
"scripts": {
"build": "tsc" <-- Comando usado para compilar arquivos TypeScript em JS!
}
}
This was just one of the examples for the npm build
, since its use varies according to the project.
Extra reading
Excellent reply, thank you !
– Allan Dantas