-
Notifications
You must be signed in to change notification settings - Fork 521
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
Add rollup_config
rule
#1314
Comments
Cool! I'd like to understand why the alternative macro approach doesn't work first. Why does it only work with a single config? Can't you call the macro twice and get two different generated configs? |
The macro adds plugins as implicit dependencies to rollup_bundle, so I don’t need to repeatedly writing them all over the places. In case another config needs a different set of plugins this will just break. Of course, I can leave that to the end user, but that’s just boilerplates and error prune. |
that's the part I'd like to understand better. what are you able to do with a We do this a bunch in Angular https://github.com/angular/angular/blob/master/tools/defaults.bzl#L307-L325 If it's easy enough to do in user-space I'd rather document how to make the macro than need to maintain another rule. |
The There are some caveats with the current macro approach:
I agree that adding a rule is overkill, but it will help to make the build file more declarative and readable. Moreover, given that we are going to add more node base tools in the future, having a pattern to deal with those configs and plugins would make life easier for both rule maintainers and consumers. |
I had been hoping that overriding the config would be mostly possible with command-line flags, that's the simplest model. But I assume you have to vary your rollup config in ways the CLI doesn't permit. What if rules_nodejs had a generic If you had Just thinking:
Note that terser_minified already has a built-in way to turn your config into a template, maybe it should be pulled out into this config_file rule? We need some more feedback about whether it's a good API. |
We have packed babel and terser in rollup action directly. So there are
just too many configs for the rollup CLI to take. This is because that
babel needs to be run before bundling the code, as it may add/remove
imports. If the config for babel is different, all the following steps
won’t benefit from caching fine grind staging files. Therefore doing them
all together.
I like the latter api, though I’d love to attach plugins as deps to it
(perhaps add a provider just for that purpose?) The former API takes us
back to the age before repository_rule is landed, that we have to put BUILD
file content in BUILD file, which is just awkward.
The replacement part should be able to use ctx.var, E.g. COMPILATION_MODE.
Our genfile rule uses “$(VAR)” for that purpose. Perhaps do the stamping
there as well?
I could write up a small green doc if needed so we can put more use case
there and discuss further.
Alex Eagle <[email protected]>于2019年11月2日 周六上午12:08写道:
I had been hoping that overriding the config would be mostly possible with
command-line flags, that's the simplest model. But I assume you have to
vary your rollup config in ways the CLI doesn't permit.
What if rules_nodejs had a generic config_file rule that just does
replacements? I've also been imagining a case where you don't even have a
template file, and want to configure the tool entirely within the
BUILD.bazel file. I keep deciding against that, because you should always
use a file that your editor understands (you'll have a better time with
blah.babelrc getting syntax highlighted than with a multiline starlark
string literal) but perhaps there is a use case for that also.
If you had config_file then the macro for your rollup usecase would be
pretty simple right?
Just thinking:
# I guess it would go in the builtin package?
***@***.***_bazel_rules_nodejs//:index.bzl", "config_file")
config_file(
// produces an output file named the same as the rule
// so users don't need to guess at whether to depend on ":config" or ":config.js"
name = "rollup_config_all_starlark.js",
content = """
// Not sure it's a good idea to put things here instead of a file in the project but maybe in some cases?
export const {
setting: "yes"
}
""",
)
config_file(
name = "rollup_config_probably_better.js",
template = "rollup_config_with_stuff",
replacements = {
"TMPL_yes": "no",
},
)
Note that terser_minified already has a built-in way to turn your config
into a template, maybe it should be pulled out into this config_file rule?
We need some more feedback about whether it's a good API.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1314>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFH2B3MAQDS65KW4UCPJ2DQRRIALANCNFSM4JGLLFZA>
.
--
Sent from Gmail Mobile
|
Just discovered another use case. I'm trying to write a plugin in typescript for babel and want to use that in |
Hi there, found this issue while searching for "stamp" as I think I've cleaned that up now. But, I'm still not convinced from reading through this again that there's a problem with |
@alexeagle This is still a problem -- having rollup plugin built with
|
That's a restriction of |
Perhaps, #2162 is the solution to this problem as well. Let rollup use the plug-in |
This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?" |
🚀 feature request
Relevant Rules
rollup_bundle
Description
We use 8 different rollup plugins to generate the final bundle, and some of these plugins require project-specific settings. It's difficult to maintain multiple rollup configs with minor differences.
Describe the solution you'd like
Add a
rollup_config
rule to generate config and capture the dependencies it needs and letrollup_bundle
rule to include the deps ofconfig_file
.It's also possible to wrap
rollup_config
in some macros to document config generation options, eg.Describe alternatives you've considered
What we do right now is to wrap
rollup_bundle
with a macro that generates the config, then letrollup_bundle
use that and injects rollup plugins to thedeps
. Under the hood it uses agenfile
rule to generate config withctx.actions.expand_template
. However, this only works for a single config template given the tightly coupled rules and macro.The text was updated successfully, but these errors were encountered: