Problem Statement
Where are npm build scripts defined?
Explanation
npm scripts are defined in package.json under scripts object. Scripts define commands for building, testing, and running applications. Example:
```json
{
"scripts": {
"build": "webpack --mode production",
"test": "jest",
"start": "node index.js",
"lint": "eslint src/"
}
}
```
Run with npm run <script-name>, e.g., npm run build.
Pre and post hooks automatically run before/after scripts: prebuild runs before build, posttest runs after test. CI/CD commonly uses npm ci (clean install from package-lock.json, faster and more reliable than npm install), npm run build, and npm test. Scripts can chain with && or call other scripts with npm run.
Benefits include consistent commands across environments, version-controlled build process, easy CI/CD integration. Understanding npm scripts enables automating Node.js project workflows.
