Skip to content

Commit

Permalink
feat(rollup): provide es5 and minified umd bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Bedard committed Apr 21, 2019
1 parent 593d47d commit 6efc433
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/e2e/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ filegroup(
output_group = "umd",
)

filegroup(
name = "bundle-outputgroups-umd_min",
srcs = [":bundle"],
output_group = "umd_min",
)

filegroup(
name = "bundle-outputgroups-es5_umd",
srcs = [":bundle"],
output_group = "es5_umd",
)

filegroup(
name = "bundle-outputgroups-es5_umd_min",
srcs = [":bundle"],
output_group = "es5_umd_min",
)

filegroup(
name = "bundle-outputgroups-es2015",
srcs = [":bundle"],
Expand All @@ -74,7 +92,10 @@ jasmine_node_test(
":bundle-outputgroups-es2015",
":bundle-outputgroups-es5_min",
":bundle-outputgroups-es5_min_debug",
":bundle-outputgroups-es5_umd",
":bundle-outputgroups-es5_umd_min",
":bundle-outputgroups-umd",
":bundle-outputgroups-umd_min",
],
deps = [
"@npm//jasmine",
Expand Down
8 changes: 8 additions & 0 deletions internal/e2e/rollup/outputgroups.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ describe('outputgroups', () => {
checkExists('bundle.umd.js');
checkExists('bundle.umd.js.map');
});
it('should produce a umd_min sourcemap', () => {
checkExists('bundle.min.umd.js');
checkExists('bundle.min.umd.js.map');
});
it('should produce a es5_umd_min sourcemap', () => {
checkExists('bundle.min.es5umd.js');
checkExists('bundle.min.es5umd.js.map');
});
});
15 changes: 15 additions & 0 deletions internal/rollup/rollup_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ def _rollup_bundle(ctx):

# There is no UMD/CJS bundle when code-splitting but we still need to satisfy the output
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_umd)
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_umd_min)
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_cjs)
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_es5_umd)
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_es5_umd_min)

# There is no source map explorer output when code-splitting but we still need to satisfy the output
ctx.actions.expand_template(
Expand Down Expand Up @@ -492,10 +495,16 @@ def _rollup_bundle(ctx):
_run_tsc(ctx, ctx.outputs.build_es2015, ctx.outputs.build_es5)
es5_min_map = run_terser(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min)
es5_min_debug_map = run_terser(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min_debug, debug = True)

cjs_rollup_config = write_rollup_config(ctx, filename = "_%s_cjs.rollup.conf.js", output_format = "cjs")
cjs_map = run_rollup(ctx, _collect_es2015_sources(ctx), cjs_rollup_config, ctx.outputs.build_cjs)

umd_rollup_config = write_rollup_config(ctx, filename = "_%s_umd.rollup.conf.js", output_format = "umd")
umd_map = run_rollup(ctx, _collect_es2015_sources(ctx), umd_rollup_config, ctx.outputs.build_umd)
umd_min_map = run_terser(ctx, ctx.outputs.build_umd, ctx.outputs.build_umd_min, config_name = ctx.label.name + "umd_min", in_source_map = umd_map)
_run_tsc(ctx, ctx.outputs.build_umd, ctx.outputs.build_es5_umd)
es5_umd_min_map = run_terser(ctx, ctx.outputs.build_es5_umd, ctx.outputs.build_es5_umd_min, config_name = ctx.label.name + "es5umd_min")

run_sourcemapexplorer(ctx, ctx.outputs.build_es5_min, es5_min_map, ctx.outputs.explore_html)

files = [ctx.outputs.build_es5_min, es5_min_map]
Expand All @@ -507,7 +516,10 @@ def _rollup_bundle(ctx):
es5 = depset([ctx.outputs.build_es5]),
es5_min = depset([ctx.outputs.build_es5_min, es5_min_map]),
es5_min_debug = depset([ctx.outputs.build_es5_min_debug, es5_min_debug_map]),
es5_umd = depset([ctx.outputs.build_es5_umd]),
es5_umd_min = depset([ctx.outputs.build_es5_umd_min, es5_umd_min_map]),
umd = depset([ctx.outputs.build_umd, umd_map]),
umd_min = depset([ctx.outputs.build_umd_min, umd_min_map]),
)

return [
Expand Down Expand Up @@ -705,7 +717,10 @@ ROLLUP_OUTPUTS = {
"build_es5": "%{name}.js",
"build_es5_min": "%{name}.min.js",
"build_es5_min_debug": "%{name}.min_debug.js",
"build_es5_umd": "%{name}.es5umd.js",
"build_es5_umd_min": "%{name}.min.es5umd.js",
"build_umd": "%{name}.umd.js",
"build_umd_min": "%{name}.min.umd.js",
"explore_html": "%{name}.explore.html",
}

Expand Down

0 comments on commit 6efc433

Please sign in to comment.