为什么在使用 --arg 时 webpack-dev-server 会抛出错误? [英] Why is webpack-dev-server throwing an error when I use --arg?

查看:21
本文介绍了为什么在使用 --arg 时 webpack-dev-server 会抛出错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的脚本:

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

在我过去的旧设置中:

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

如何使用 webpack-dev-server 实现相同的(具有 --arg dev 东西)?

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

这是错误:

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`

推荐答案

你描述的事情在 webpack 1 中是可能的.

The thing you described was possible with webpack 1.

从 webpack 2+ 开始(并且 webpack-dev-server 将按原样将参数传递给 webpack)传递自定义参数只能通过使用 env 前缀 来完成.:

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"

但是,您的脚本无法按原样运行,您需要对其进行调整以在 webpack 配置中使用 env 属性.

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
  }
};

请参阅文档

这篇关于为什么在使用 --arg 时 webpack-dev-server 会抛出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆