Open ericclemmons opened 8 years ago
No need for .env()
anymore, IMO.
@ericclemmons looking at the Webpack CLI I am wondering if the --env
flag is intended to be equivalent to NODE_ENV
.
Could we make it so that env()
accepts whatever, and the when
function runs against whatever is in there? In most cases it will be the same but given that --env
is the only flag webpack really gives you the freedom to say whatever you want, and it is the only arg that gets passed to a function in your config file (besides options, which are limited to what webpack cli accepts), it would be nicer to not assume that the only valid options are what you would have in your NODE_ENV
@datapimp Can you make up a code example of how that'd look? I had plans for .when
to support both string|function
, so that you can do things like:
.when(
// Should return `true` when condition matches
(...) => ...,
// Conditional config
(api) => ...
);
I'm in the process of migrating a project to use webpack, and went with this project as the configuration builder
I settled on doing something like this: https://github.com/OpenCollective/opencollective-website/blob/webpack-2/frontend/webpack.config.babel.js#L11 which probably makes more sense anyway given that the target
was what I was trying to branch off of.
Still, I'd love to have just the one simple module.exports = require('@terse/webpack')
since it reads so nicely -- having only one thread to follow top to bottom is great. So I think your string|function
would be perfect for that.
I was in the middle of submitting a PR which added support for something like:
.when({ target: 'web', env: 'production' }, (api) => (
api.plugin('webpack.UglifyJsPlugin', {})
)
so if you like I can add a function as well.
This useful when configuring the
.api()
.