来自npm脚本的Webpack配置

时间:2017-02-20 09:45:35

标签: webpack webpack-dev-server webpack-2

我在package.json设置中有两个脚本,如下所示,

    "scripts": {
"webpackDevServer": "babel-node ./node_modules/.bin/webpack-dev-server --config=webpack.config.dev.js --progress --colors",
    "webPack": "babel-node ./node_modules/.bin/webpack --config=webpack.config.dev.js"
}

当我用>执行它时npm运行webPack

我收到此错误,

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^
SyntaxError: missing ) after argument list
    at Object.exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:543:28)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\Xpert\WebstormProjects\Re\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Function.Module.runMain (module.js:605:10)
    at C:\Users\Xpert\WebstormProjects\Re\node_modules\babel-cli\lib\_babel-node.js:155:24
    at Object.<anonymous> (C:\Users\Xpert\WebstormProjects\Re\node_modules\babel-cli\lib\_babel-node.js:156:7)

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "webPack"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! siv@0.0.1 webPack: `babel-node ./node_modules/.bin/webpack --config=webpack.config.dev.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the siv@0.0.1 webPack script 'babel-node ./node_modules/.bin/webpack --config=webpack.config.dev.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the simprov package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel-node ./node_modules/.bin/webpack --config=webpack.config.dev.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs si
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls simprov
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Xpert\WebstormProjects\Re\npm-debug.log

当我这样做时,会发生同样的情况。 npm运行webpackDevServer

我在这里做错了什么?

- 谢谢你。

2 个答案:

答案 0 :(得分:0)

最开始不需要babel-node,只需运行“ node_modules / .bin / webpack-dev-server”

答案 1 :(得分:0)

Windows无法解析要使用的正确的 webpack-dev-server 文件扩展名((

显式调用*.js

"node node_modules/webpack-dev-server/bin/webpack-dev-server.js --config=webpack.config.dev.js --progress"

或通过CLI

运行它
"webpack-dev-server --config=webpack.config.dev.js --progress --color"