ElliotYoYo
ElliotYoYo

Reputation: 221

Webpack environment variable are unknown argument

I'm trying to create a webpack setup but can't manage to make it work with the environment variables. I have read the doc more than 10 times but can't find the solution.

My package json has this script:

"build": "webpack --config webpack.config.js --env.MODE=production "

But when I'm running it, node is telling me:

webpack: Unknown argument: --env.MODE=production
Usage: webpack --config <path to webpack configuration file> e.g. ./webpack.config.js
Description: Provide path to a webpack configuration file
Documentation: https://webpack.js.org/configuration/

EDIT: I finally found the solution. The webpack-ci installed version was "webpack-cli": "^4.0.0-beta.2". I downgraded it and it's now working fine.

Upvotes: 8

Views: 11665

Answers (2)

AuthorProxy
AuthorProxy

Reputation: 8047

Just use with spacing..

"build": "webpack --mode=production --config webpack.config.js --env MODE=production"

Now you can parse it like:

module.exports = ({ MODE }, { mode }) => {...}

Have a good day!

Upvotes: 6

Tony
Tony

Reputation: 20092

This is how I do it you can view the file here

  "prod": "webpack -p --mode=production --config webpack.prod.js",
  "start": "webpack --mode=development --config webpack.dev.js",

Upvotes: 0

Related Questions