package.json is a JSON project record. Create it with npm init to capture package details, track installed dependencies, separate development-only tools, and define commands for repeatable tasks. section 12.3
Use its main areas to organize a JavaScript project:
- dependencies records packages needed by the project, such as Web Component polyfills. section 12.3
- devDependencies records tools used only during development or building, such as Rollup installed with --save-dev. section 12.3 section 12.4
- scripts maps names such as test or build to terminal commands, including commands that combine several component builds. section 12.3 section 12.4
A minimal script
A package.json can define a test command directly: { "name": "wcia", "version": "1.0.0", "scripts": { "test": "echo 'Hello from package.json'" } }. Run it through npm rather than typing the command manually. section 12.3
Listing 12.7. A simple package.json script
{
"name": "wcia",
"version": "1.0.0",
"scripts": {
"test": "echo 'Hello from package.json'" #1
}
}
Inspect a complete minimal package.json script and its test command. section 12.3
Listing 12.8. A package.json file after installing Rollup
{
"name": "wcia",
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"rollup": "^1.0.2" #1
}
}
Compare dependencies with a Rollup devDependencies entry after local installation. section 12.4
Listing 12.9. Adding a Rollup script in package.json
{
"name": "wcia",
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"rollup": "^1.0.2"
},
"scripts": {
"build": "./node_modules/.bin/rollup chapter12and13/components/slider/src/#1
slider.js --file chapter12and13/components/slider/slider.js --format #1
umd --name slider -m" #1
}
Follow a package.json build script that invokes a locally installed Rollup binary. section 12.4




