{%hackmd /au2gfdvHR0mEjvR_NzROqA?both %} ###### tags: `Node.js` [Node.js] NPM script 自訂指令 === [TOC] ## NPM script 的功用為何? - 用在客製化自訂指令 ```json= "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack" }, ``` ## 範例 - `hello.js` ```javascript= console.log("hello1"); console.log("hello2"); console.log("hello3"); ``` - `package.js` - `node` = 用 node 去執行 js - `hello.js` = 檔案位置,放在根目錄下 ```json= "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack", "hello": "node hello.js" }, ``` > ![](https://i.imgur.com/3dUviQh.png) > <small>執行畫面 & `hello.js`的位置</small>