webpack-dev-server不是內部指令,然後設定package.json的scipt後
npm run server就可以啟動伺服器這是為什麼?
scripts "scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
**"server":"webpack-dev-server"**
},
下面是我package.json的設定
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server":"webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-loader": "^6.4.1",
"css-loader": "^0.28.0",
"style-loader": "^0.16.1",
"url-loader": "^0.5.8",
"webpack": "^2.3.3",
"webpack-dev-server": "^2.4.2"
}
}
可以這麼理解,
npm run
命令会开启一个新的shell
,默认把node_modules/.bin
添加到环境变量$PATH
所以你
npm run
运行的webpack-dev-server
来自当前项目的node_modules/.bin
目錄下你打過這個webpack-dev-server套件啊 所有有個指令
那我該怎麼設定才能直接使用webpack-dev-server也啟動作用