Skip to content

Commit

Permalink
feat(cli): Support webpack 2 --env (#92)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kent C. Dodds authored and jonathanglasmeyer committed May 20, 2016
1 parent ac24d6e commit f01b917
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"commander": "2.9.0",
"joi": "8.0.5",
"lodash": "4.11.1",
"npmlog": "2.0.3"
"npmlog": "2.0.3",
"yargs": "4.7.1"
},
"devDependencies": {
"autoprefixer": "6.3.6",
Expand Down
4 changes: 3 additions & 1 deletion src/bin/validate-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const validate = require('../')
const argv = require('yargs').argv

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

const config = require(webpackConfigPath)
return validate(config, validate.schema, {
const configToValidate = typeof config === 'function' ? config(argv.env, argv) : config
return validate(configToValidate, validate.schema, {
returnValidation: true,
quiet,
})
Expand Down

0 comments on commit f01b917

Please sign in to comment.