Skip to content

Commit f01b917

Browse files
Kent C. Doddsjonathanglasmeyer
authored andcommitted
feat(cli): Support webpack 2 --env (#92)
In webpack 2, your config can be a function that accepts the `env` flag as parsed from [yargs][yargs] (see [here][webpack-usage]). This will allow people to use the --env flag with the CLI for their Webpack 2 configs. [yargs]: https://github.com/yargs/yargs [webpack-usage]: https://github.com/webpack/webpack/blob/76e845914b5ff18de8d13a9c188666a60c736fd0/bin/convert-argv.js#L103
1 parent ac24d6e commit f01b917

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"commander": "2.9.0",
4646
"joi": "8.0.5",
4747
"lodash": "4.11.1",
48-
"npmlog": "2.0.3"
48+
"npmlog": "2.0.3",
49+
"yargs": "4.7.1"
4950
},
5051
"devDependencies": {
5152
"autoprefixer": "6.3.6",

src/bin/validate-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path')
22
const validate = require('../')
3+
const argv = require('yargs').argv
34

45
module.exports = function validateConfig(webpackConfigFile, quiet) {
56
if (!quiet) console.log(`Reading: ${webpackConfigFile}`)
@@ -10,7 +11,8 @@ module.exports = function validateConfig(webpackConfigFile, quiet) {
1011
]
1112

1213
const config = require(webpackConfigPath)
13-
return validate(config, validate.schema, {
14+
const configToValidate = typeof config === 'function' ? config(argv.env, argv) : config
15+
return validate(configToValidate, validate.schema, {
1416
returnValidation: true,
1517
quiet,
1618
})

0 commit comments

Comments
 (0)