5.npm scripts 使用指南

weixin_30588675發表於2020-04-05

簡單介紹

scripts裡面的
"start": "node app"
npm run start 相當於 node app

{
  "name": "5-npm-scripts",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {},
  "devDependencies": {
    "nodemon": "^1.9.2"
  },
  "scripts": {
    "start": "node app",
    "dev": "nodemon app",
    "test": "node test",
    "test-watch": "nodemon test"
  },
  "author": "",
  "license": "ISC"
}

更加詳細的介紹,建議看阮一峰的scripts介紹

npm scripts 使用指南

nodemon

這個可以監控js變化

eg

app.js

'use strict';
var math = require('./math');
var value = math.add(5, 6);
console.log(value);

math.js

exports.add = function(a, b) {
  return a + b;
}

exports.subtract = function(a, b) {
  return a - b;
}

exports.multiply = function(a, b) {
  return a * b;
}

test.js

'use strict';

var assert = require('assert');

var math = require('./math');

assert(math.add(3, 4) === 7);
assert(math.subtract(3, 4) === -1);
assert(math.multiply(3, 4) === 12);

console.log("all tests passed!");

轉載於:https://www.cnblogs.com/caijw/p/7258618.html

相關文章