Description
🚀 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 let rollup_bundle
rule to include the deps of config_file
.
rollup_config(
name = "bundle_config",
template = "//some/shared:template.rollup.js",
substitutions = {
"replaces": struct(
"process.env.NODE_ENV" = "'production'",
).to_json(),
},
deps = [
"@npm//@babel/preset-env",
"@npm//babel-plugin-transform-jsbi-to-bigint",
"@npm//core-js",
"@npm//regenerator-runtime",
"@npm//rollup-plugin-babel",
"@npm//rollup-plugin-commonjs",
"@npm//rollup-plugin-node-resolve",
"@npm//rollup-plugin-replace",
"@npm//rollup-plugin-strip",
"@npm//rollup-plugin-terser",
],
)
rollup_bundle(
name = "bundle",
config = ":bundle_config",
entry_point = ":index.ts",
deps = [":app"],
)
It's also possible to wrap rollup_config
in some macros to document config generation options, eg.
def rollup_config(name, replaces = {}):
_rollup_config(
name = "bundle_config",
template = "//some/shared:template.rollup.js",
substitutions = {
"replaces": struct(**replaces).to_json(),
},
deps = [
"@npm//@babel/preset-env",
"@npm//babel-plugin-transform-jsbi-to-bigint",
"@npm//core-js",
"@npm//regenerator-runtime",
"@npm//rollup-plugin-babel",
"@npm//rollup-plugin-commonjs",
"@npm//rollup-plugin-node-resolve",
"@npm//rollup-plugin-replace",
"@npm//rollup-plugin-strip",
"@npm//rollup-plugin-terser",
],
)
Describe alternatives you've considered
What we do right now is to wrap rollup_bundle
with a macro that generates the config, then let rollup_bundle
use that and injects rollup plugins to the deps
. Under the hood it uses a genfile
rule to generate config with ctx.actions.expand_template
. However, this only works for a single config template given the tightly coupled rules and macro.