Why is webpack-dev-server throwing an error when I use --arg?

亡梦爱人 提交于 2020-01-06 07:55:08

问题


This is my script:

"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --arg devus"

In my old setup I used to do:

"dev": "node build/dev-server.js --arg dev"

How can I achieve the same (having the --arg dev thing) with webpack-dev-server?

This is the error:

Unknown argument: arg
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-phantom@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --arg devus`

回答1:


The thing you described was possible with webpack 1.

As of webpack 2+ (and webpack-dev-server will pass the arguments to the webpack as is) passing the custom arguments can be done only by prefixing the arguments with env.:

"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --env.arg devus"

However your script will not work as is, you would need to adapt it to use env property inside of your webpack configuration.

In other words this is how your config should look like

module.exports = env => {
  console.log(env);

  return {
    // your config heree
  }
};

See the documentation



来源:https://stackoverflow.com/questions/48660505/why-is-webpack-dev-server-throwing-an-error-when-i-use-arg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!