-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack 2.0 doesn't support custom command line arguments? #2254
Comments
👍 |
Yes this is intended. Custom argumens can be passed via module.exports = function(env) {
// ...
if (env.compress === 'true') {
var CompressionPlugin = require('compression-webpack-plugin');
config.plugins.push(
new CompressionPlugin({
asset: '{file}',
algorithm: 'gzip',
regExp: /\.js$|\.html$/
}))
}
} |
I just rewrote the build at work, and added yargs into webpack.config.js, and this works great (still using webpack 1). Especially demanding args is nice, but also printing usage message etc.. We have a quite complex build capable of building 5 different webapps, proxying different backends, and different versions of production to build for, and being able to use yargs at the top level for this is perfect, as we also use I know I can get (mostly) the same out of using the env-flag, but some things are missing, such as demanding, defaults (which is really nice), choices (even nicer) and usage printing. So it's more limiting; I have to manually check that usage is correct, I have to manually set defaults, check if value is valid, that it's passed a string or boolean, etc. I understand that in most cases, using |
@SimenB Look like in your case a custom CLI tool for the build is more suitable. You basically build one. You can just move the CLI stuff from the There were a couple of reasons why I decided to disallow custom arguments:
|
👎 |
I'm in the same boat. I'd love to keep using |
see #2254 (comment) You can still pass arguments. Just prefix |
We'll use that, thanks. |
…CLI, you have to use env.argName instead (webpack/webpack#2254 (comment)).
The only way I have been able to pass arguments is using the below link. |
This isn't working for me. ...
module.exports = function makeWebpackConfig(cfgEnv) {
...
console.log('env is ', cfgEnv);
...
} $ ./node_modules/.bin/webpack --env.a=1
env is undefined
$ ./node_modules/.bin/webpack --env.a 1
env is undefined
$ ./node_modules/.bin/webpack -v
2.1.0-beta.26 Am I doing something wrong? |
I still think the advantage of allowing custom args is bigger than the advantage of typo checking |
"Solved" it by using classic yargs to get arguments prefixed with
And what about typo checking of custom args? 😆 |
@mnn I am running into the same issue. |
If anyone else comes here searching for the answer, I solved it as follows: // webpack.config.js
module.exports = function(env) {
console.log(env.hello); // 'world'
} npm run build -- --env.hello world |
@joshfarrant and then where is the rest of the webpack config object, and how is it exported? Just console logging |
@Pomax -- you just have to return the config
|
As I have used cross-env before that works for me (npm install cross-env) and in webpack.config process.env.NODE_ENV === 'production' ? this : that |
For people who have simply want args in their config file without the large
|
@nealoke this was already mentioned in #2254 (comment) |
So how do you get the env outside module.exports? |
I have |
i believe your syntax should be --env.development but really, whats better is doing the following: NODE_ENV=development; webpack ... we have the following npm run script in package.json using cross-env so that it also works on windows.
then in the code:
and use APP_ENV everywhere else full example: https://github.com/SamanthaAdrichem/webpack-3.9.1-splitted-config-angular |
Thank you! Now it works fine) |
none of the above worked for me npm run build --env.test='test' process.env.test is always undefined |
Hello, Try |
In Webpack 1.x, I can pass in my own command line arguments like this:
webpack --config ./webpack.config.prod.js --compress true
Here
--compress
is the custom command line arguments, it can be used like this in thewebpack.config.js
:However, in Webpack 2.0, this approach doesn't work any more. When I type in
webpack --config ./webpack.config.prod.js --compress true
. The webpack will just throw an error:Unknown argument: compress
And then stops... Would there be a way in Webpack 2.0 to support custom command line arguments?
The text was updated successfully, but these errors were encountered: