Optionally pass CLI command arguments to config - #1926
Conversation
If config file exports a function then call this function with `commandOptions` object. We expect this function to return a `config` object or `configs` array, the same as existing config files
lukastaegert
left a comment
There was a problem hiding this comment.
Sorry for not having a look at this earlier. I actually like the idea! It also gives you the chance to add "custom" CLI options to your build without the need to modify anything on rollup's side (as long as there is no conflict with rollup's own options). For instance I could imagine people using npx rollup -c --production to trigger a production build etc.
|
@guybedford What do you think? |
|
@lukastaegert sorry I missed this one. I haven’t looked closely, but does this stop us from verifying invalid CLI arguments or misspellings like --formt instead of —format? Just checking as that would be a shame to lose here. |
|
As a matter of fact, misspelled CLI options never seemed to have been verified in the first place. So there is no regression here which makes this feature much more interesting. If we wanted to introduce such a check, however, we should consider interactions with this feature now. E.g. maybe the config file should be responsible for cleaning up the command object. |
|
Yeah that was just my concern if we're closing a door here at all. |
|
The other worry is that if there becomes a common flag in use by a very popular plugin, then Rollup cannot use that flag itself as a value due to the namespace collision. Could we not have a special argument for this like using the The more I think about this I don't think we should release this in the current form. |
This is not an issue as this is not about plugins at all, this is solely about local config files. Plugins could not and still cannot consume CLI options. One primary use case for config files is that you can inspect rollup's options to react e.g. to the use of |
|
We could however reserve a namespace for custom variables i.e. that they should be of the form |
Right, the same concern applies to configuration files though in that a new rollup flag could break existing configurations. So I do think we need some way to disambiguate the namespaces.
|
|
I think |
|
Sounds good! |
|
Thanks for the positive discussion
I agree this is the major potential problem with this change but, personally, I'd say that plugin authors could be left (or perhaps advised) to handle this concern themselves by providing non-clashing names, eg by prefixing plugin-specific params with the plugin's name: |
Please see #1925 for a discussion relating to this pull request
If config file exports a function then call this function with
commandOptionsobject. We expect this function to return aconfigobject orconfigsarray, the same as existing config files