Skip to content

Commit

Permalink
feat(rollup): provide es5 and minified umd bundles
Browse files Browse the repository at this point in the history
Closes #685
  • Loading branch information
Jason Bedard authored and Keen Yee Liau committed Apr 24, 2019
1 parent f5314b4 commit d70cf62
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/e2e/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jasmine_node_test(
":bundle",
":bundle.cjs.js",
":bundle.umd.js",
":bundle.es5umd.js",
":bundle.min.es5umd.js",
":bundle.min_debug.js",
],
deps = [
Expand All @@ -48,6 +50,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 +94,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
31 changes: 31 additions & 0 deletions internal/e2e/rollup/bundle-es5umd_golden.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @license A dummy license banner that goes at the top of the file.
* This is version v1.2.3
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('some_global_var')) :
typeof define === 'function' && define.amd ? define(['exports', 'some_global_var'], factory) :
(global = global || self, factory(global.bundle = {}, global.runtime_name_of_global_var));
}(this, function (exports, some_global_var) {
'use strict';
var fum = 'Wonderland';
var hello = 'Hello';
var name = 'Alice';
console.log(hello + ", " + name + " in " + fum);
// Test for sequences = false
var A = /** @class */ (function () {
function A() {
}
A.prototype.a = function () {
return document.a;
};
return A;
}());
function inline_me() {
return 'abc';
}
console.error(new A().a(), inline_me(), some_global_var.thing);
exports.A = A;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=bundle.umd.js.map
5 changes: 5 additions & 0 deletions internal/e2e/rollup/bundle-min-es5umd_golden.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @license A dummy license banner that goes at the top of the file.
* This is version v1.2.3
*/
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("some_global_var")):"function"==typeof define&&define.amd?define(["exports","some_global_var"],o):o((e=e||self).bundle={},e.runtime_name_of_global_var)}(this,function(e,o){"use strict";console.log("Hello, Alice in Wonderland");var n=function(){function e(){}return e.prototype.a=function(){return document.a},e}();console.error((new n).a(),"abc",o.thing),e.A=n,Object.defineProperty(e,"__esModule",{value:!0})});
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');
});
});
6 changes: 6 additions & 0 deletions internal/e2e/rollup/rollup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ describe('bundling', () => {
it('should produce a CJS bundle', () => {
check(path, 'bundle.cjs.js', 'bundle-cjs_golden.js_');
});
it('should produce an es5 UMD bundle', () => {
check(path, 'bundle.es5umd.js', 'bundle-es5umd_golden.js_');
});
it('should produce an es5 minified UMD bundle', () => {
check(path, 'bundle.min.es5umd.js', 'bundle-min-es5umd_golden.js_');
});
});
15 changes: 15 additions & 0 deletions internal/rollup/rollup_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,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 @@ -498,10 +501,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 @@ -513,7 +522,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 @@ -711,7 +723,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 d70cf62

Please sign in to comment.