Repository navigation
Description
This is related to #29454 so please read that first for more context.
To use angular and angular libraries from npm we must currently run ngc on them in postinstall step of yarn or npm.
"scripts": {
"postinstall": "ngc -p ./angular-metadata.tsconfig.json"
}
This generates .ngfactory.js files that we can then use as inputs to Bazel rules that require them. The generated .ngfactory.js files need to work with a number rules in the typical use cases. They need to be compatible with the rollup_bundle rule in order to produce a production bundle. They also need to be valid inputs to ts_devserver and ts_web_test_suite which require named UMD or named AMD. The postinstall step also generated .ngsummary.js files to use in JIT mode with ts_web_test_suite ("angularCompilerOptions": { "enableSummariesForJit": true } must be set in angular-metadata.tsconfig.json to generate these outputs).
ngc is able to produce both umd and amd outputs depending on the configuration in angular-metadata.tsconfig.json. ngc is just a wrapper around tsc which controls the output format.
UMD format
With the following in angular-metadata.tsconfig.json,
"compilerOptions": {
...
"module": "umd",
"moduleResolution": "node",
},
tsc generates UMD in the simplified CommonJS wrapper format where require is passed through to the factory function:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./mod"], factory);
}
})(function (require, exports) {
var mod_1 = require("./mod");
exports.t = mod_1.something + 1;
});
Some documentation on this format incase you are not familiar with it:
- https://requirejs.org/docs/api.html#cjsmodule
- https://www.typescriptlang.org/docs/handbook/modules.html (scroll down to Code Generation for Modules)
- https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define
Example of a generated ngfactory.js files:
node_modules/@angular/material/toolbar/typings/index.ngfactory.js:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define("@angular/material/toolbar/typings/index.ngfactory", ["require", "exports", "@angular/core", "@angular/material/toolbar", "@angular/cdk/bidi", "@angular/material/core", "@angular/platform-browser", "@angular/cdk/platform", "@angular/common"], factory);
}
})(function (require, exports) {
"use strict";
/**
* @fileoverview This file was generated by the Angular template compiler. Do not edit.
*
* @suppress {suspiciousCode,uselessCode,missingProperties,missingOverride,checkTypes}
* tslint:disable
*/
exports.__esModule = true;
var i0 = require("@angular/core");
var i1 = require("@angular/material/toolbar");
var i2 = require("@angular/cdk/bidi");
var i3 = require("@angular/material/core");
var i4 = require("@angular/platform-browser");
var i5 = require("@angular/cdk/platform");
var i6 = require("@angular/common");
var MatToolbarModuleNgFactory = i0.ɵcmf(i1.MatToolbarModule, [], function (_l) { return i0.ɵmod([i0.ɵmpd(512, i0.ComponentFactoryResolver, i0.ɵCodegenComponentFactoryResolver, [[8, []], [3, i0.ComponentFactoryResolver], i0.NgModuleRef]), i0.ɵmpd(1073742336, i2.BidiModule, i2.BidiModule, []), i0.ɵmpd(1073742336, i3.MatCommonModule, i3.MatCommonModule, [[2, i3.MATERIAL_SANITY_CHECKS], [2, i4.HAMMER_LOADER]]), i0.ɵmpd(1073742336, i1.MatToolbarModule, i1.MatToolbarModule, [])]); });
exports.MatToolbarModuleNgFactory = MatToolbarModuleNgFactory;
var styles_MatToolbar = ["@media (-ms-high-contrast:active){.mat-toolbar{outline:solid 1px}}.mat-toolbar-row,.mat-toolbar-single-row{display:flex;box-sizing:border-box;padding:0 16px;width:100%;flex-direction:row;align-items:center;white-space:nowrap}.mat-toolbar-multiple-rows{display:flex;box-sizing:border-box;flex-direction:column;width:100%}.mat-toolbar-multiple-rows{min-height:64px}.mat-toolbar-row,.mat-toolbar-single-row{height:64px}@media (max-width:599px){.mat-toolbar-multiple-rows{min-height:56px}.mat-toolbar-row,.mat-toolbar-single-row{height:56px}}"];
var RenderType_MatToolbar = i0.ɵcrt({ encapsulation: 2, styles: styles_MatToolbar, data: {} });
exports.RenderType_MatToolbar = RenderType_MatToolbar;
function View_MatToolbar_0(_l) { return i0.ɵvid(2, [i0.ɵncd(null, 0), i0.ɵncd(null, 1)], null, null); }
exports.View_MatToolbar_0 = View_MatToolbar_0;
function View_MatToolbar_Host_0(_l) { return i0.ɵvid(0, [(_l()(), i0.ɵeld(0, 0, null, null, 2, "mat-toolbar", [["class", "mat-toolbar"]], [[2, "mat-toolbar-multiple-rows", null], [2, "mat-toolbar-single-row", null]], null, null, View_MatToolbar_0, RenderType_MatToolbar)), i0.ɵdid(1, 4243456, null, 1, i1.MatToolbar, [i0.ElementRef, i5.Platform, i6.DOCUMENT], null, null), i0.ɵqud(603979776, 1, { _toolbarRows: 1 })], null, function (_ck, _v) { var currVal_0 = (i0.ɵnov(_v, 1)._toolbarRows.length > 0); var currVal_1 = (i0.ɵnov(_v, 1)._toolbarRows.length === 0); _ck(_v, 0, 0, currVal_0, currVal_1); }); }
exports.View_MatToolbar_Host_0 = View_MatToolbar_Host_0;
var MatToolbarNgFactory = i0.ɵccf("mat-toolbar", i1.MatToolbar, View_MatToolbar_Host_0, { color: "color" }, {}, ["*", "mat-toolbar-row"]);
exports.MatToolbarNgFactory = MatToolbarNgFactory;
});
While this format works for ts_devserver and ts_web_test_suite and rollup-plugin-commonjs which is used in rollup_bundle can handle bundling UMD, it can't handle the simplified commonjs wrapper format and it doesn't resolve the requires within the module since require is a parameter of the factory.
The module ends up in the bundle in the following format:
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
}
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var index_ngfactory = createCommonjsModule(function (module, exports) {
(function (factory) {
{
var v = factory(commonjsRequire, exports);
if (v !== undefined) module.exports = v;
}
})(function (require, exports) {
/**
* @fileoverview This file was generated by the Angular template compiler. Do not edit.
*
* @suppress {suspiciousCode,uselessCode,missingProperties,missingOverride,checkTypes}
* tslint:disable
*/
exports.__esModule = true;
var i0 = require("@angular/core");
var i1 = require("@angular/material/toolbar");
var i2 = require("@angular/cdk/bidi");
var i3 = require("@angular/material/core");
var i4 = require("@angular/platform-browser");
var i5 = require("@angular/cdk/platform");
var i6 = require("@angular/common");
var MatToolbarModuleNgFactory = i0.ɵcmf(i1.MatToolbarModule, [], function (_l) { return i0.ɵmod([i0.ɵmpd(512, i0.ComponentFactoryResolver, i0.ɵCodegenComponentFactoryResolver, [[8, []], [3, i0.ComponentFactoryResolver], i0.NgModuleRef]), i0.ɵmpd(1073742336, i2.BidiModule, i2.BidiModule, []), i0.ɵmpd(1073742336, i3.MatCommonModule, i3.MatCommonModule, [[2, i3.MATERIAL_SANITY_CHECKS], [2, i4.HAMMER_LOADER]]), i0.ɵmpd(1073742336, i1.MatToolbarModule, i1.MatToolbarModule, [])]); });
exports.MatToolbarModuleNgFactory = MatToolbarModuleNgFactory;
var styles_MatToolbar = ["@media (-ms-high-contrast:active){.mat-toolbar{outline:solid 1px}}.mat-toolbar-row,.mat-toolbar-single-row{display:flex;box-sizing:border-box;padding:0 16px;width:100%;flex-direction:row;align-items:center;white-space:nowrap}.mat-toolbar-multiple-rows{display:flex;box-sizing:border-box;flex-direction:column;width:100%}.mat-toolbar-multiple-rows{min-height:64px}.mat-toolbar-row,.mat-toolbar-single-row{height:64px}@media (max-width:599px){.mat-toolbar-multiple-rows{min-height:56px}.mat-toolbar-row,.mat-toolbar-single-row{height:56px}}"];
var RenderType_MatToolbar = i0.ɵcrt({ encapsulation: 2, styles: styles_MatToolbar, data: {} });
exports.RenderType_MatToolbar = RenderType_MatToolbar;
function View_MatToolbar_0(_l) { return i0.ɵvid(2, [i0.ɵncd(null, 0), i0.ɵncd(null, 1)], null, null); }
exports.View_MatToolbar_0 = View_MatToolbar_0;
function View_MatToolbar_Host_0(_l) { return i0.ɵvid(0, [(_l()(), i0.ɵeld(0, 0, null, null, 2, "mat-toolbar", [["class", "mat-toolbar"]], [[2, "mat-toolbar-multiple-rows", null], [2, "mat-toolbar-single-row", null]], null, null, View_MatToolbar_0, RenderType_MatToolbar)), i0.ɵdid(1, 4243456, null, 1, i1.MatToolbar, [i0.ElementRef, i5.Platform, i6.DOCUMENT], null, null), i0.ɵqud(603979776, 1, { _toolbarRows: 1 })], null, function (_ck, _v) { var currVal_0 = (i0.ɵnov(_v, 1)._toolbarRows.length > 0); var currVal_1 = (i0.ɵnov(_v, 1)._toolbarRows.length === 0); _ck(_v, 0, 0, currVal_0, currVal_1); }); }
exports.View_MatToolbar_Host_0 = View_MatToolbar_Host_0;
var MatToolbarNgFactory = i0.ɵccf("mat-toolbar", i1.MatToolbar, View_MatToolbar_Host_0, { color: "color" }, {}, ["*", "mat-toolbar-row"]);
exports.MatToolbarNgFactory = MatToolbarNgFactory;
});
});
which throws 'Dynamic requires are not currently supported by rollup-plugin-commonjs' at runtime in the browser.
For reference, the rollup-plugin-commonjs can handle requires in a UMD module that are inlined like so:
// From https://github.com/rollup/rollup-plugin-commonjs/issues/38
(function(global, factory) {
/* AMD */ if (typeof define === 'function' && define["amd"])
define(["foo"], factory);
/* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
module["exports"] = factory(require("foo"), true);
/* Global */ else
(global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
})(this, function(ByteBuffer, isCommonJS) {
return isCommonJS;
})
(notice factory(require("foo"), true);)
but tsc does not generated UMD in that format.
AMD format
With the following in angular-metadata.tsconfig.json,
"compilerOptions": {
...
"module": "amd",
"moduleResolution": "node",
},
tsc generates AMD in the standard AMD format. require is still passed to the module factory function but it is not used and all deps are listed as strings in define.
The same generated ngfactory in AMD format looks like this:
node_modules/@angular/material/toolbar/typings/index.ngfactory.js:
define("@angular/material/toolbar/typings/index.ngfactory", ["require", "exports", "@angular/core", "@angular/material/toolbar", "@angular/cdk/bidi", "@angular/material/core", "@angular/platform-browser", "@angular/cdk/platform", "@angular/common"], function (require, exports, i0, i1, i2, i3, i4, i5, i6) {
"use strict";
/**
* @fileoverview This file was generated by the Angular template compiler. Do not edit.
*
* @suppress {suspiciousCode,uselessCode,missingProperties,missingOverride,checkTypes}
* tslint:disable
*/
exports.__esModule = true;
var MatToolbarModuleNgFactory = i0.ɵcmf(i1.MatToolbarModule, [], function (_l) { return i0.ɵmod([i0.ɵmpd(512, i0.ComponentFactoryResolver, i0.ɵCodegenComponentFactoryResolver, [[8, []], [3, i0.ComponentFactoryResolver], i0.NgModuleRef]), i0.ɵmpd(1073742336, i2.BidiModule, i2.BidiModule, []), i0.ɵmpd(1073742336, i3.MatCommonModule, i3.MatCommonModule, [[2, i3.MATERIAL_SANITY_CHECKS], [2, i4.HAMMER_LOADER]]), i0.ɵmpd(1073742336, i1.MatToolbarModule, i1.MatToolbarModule, [])]); });
exports.MatToolbarModuleNgFactory = MatToolbarModuleNgFactory;
var styles_MatToolbar = ["@media (-ms-high-contrast:active){.mat-toolbar{outline:solid 1px}}.mat-toolbar-row,.mat-toolbar-single-row{display:flex;box-sizing:border-box;padding:0 16px;width:100%;flex-direction:row;align-items:center;white-space:nowrap}.mat-toolbar-multiple-rows{display:flex;box-sizing:border-box;flex-direction:column;width:100%}.mat-toolbar-multiple-rows{min-height:64px}.mat-toolbar-row,.mat-toolbar-single-row{height:64px}@media (max-width:599px){.mat-toolbar-multiple-rows{min-height:56px}.mat-toolbar-row,.mat-toolbar-single-row{height:56px}}"];
var RenderType_MatToolbar = i0.ɵcrt({ encapsulation: 2, styles: styles_MatToolbar, data: {} });
exports.RenderType_MatToolbar = RenderType_MatToolbar;
function View_MatToolbar_0(_l) { return i0.ɵvid(2, [i0.ɵncd(null, 0), i0.ɵncd(null, 1)], null, null); }
exports.View_MatToolbar_0 = View_MatToolbar_0;
function View_MatToolbar_Host_0(_l) { return i0.ɵvid(0, [(_l()(), i0.ɵeld(0, 0, null, null, 2, "mat-toolbar", [["class", "mat-toolbar"]], [[2, "mat-toolbar-multiple-rows", null], [2, "mat-toolbar-single-row", null]], null, null, View_MatToolbar_0, RenderType_MatToolbar)), i0.ɵdid(1, 4243456, null, 1, i1.MatToolbar, [i0.ElementRef, i5.Platform, i6.DOCUMENT], null, null), i0.ɵqud(603979776, 1, { _toolbarRows: 1 })], null, function (_ck, _v) { var currVal_0 = (i0.ɵnov(_v, 1)._toolbarRows.length > 0); var currVal_1 = (i0.ɵnov(_v, 1)._toolbarRows.length === 0); _ck(_v, 0, 0, currVal_0, currVal_1); }); }
exports.View_MatToolbar_Host_0 = View_MatToolbar_Host_0;
var MatToolbarNgFactory = i0.ɵccf("mat-toolbar", i1.MatToolbar, View_MatToolbar_Host_0, { color: "color" }, {}, ["*", "mat-toolbar-row"]);
exports.MatToolbarNgFactory = MatToolbarNgFactory;
});
This AMD format works with ts_devserver and ts_web_test_suite which both use RequireJS as the loader. rollup-plugin-commonjs can't handle this format but there is another rollup plugin rollup-plugin-amd which can. This plugin needs to be added to rollup_bundle to handle these files as inputs: bazel-contrib/rules_nodejs#625.
By default, however, rollup-plugin-amd converts the AMD to ES6 using default import statements (import foo from './foo') while the tsc generated amd format assumes its es6 import equivalents are namespaces imports (import * as foo from './foo'). In order to get rollup-plugin-amd to work with this file, a postinstall patch is needed to the @buxlabs/amd-to-es6 npm library used by rollup-plugin-amd:
log('\n# patch: @buxlabs/amd-to-es6 to generate namespace imports instead of default imports');
sed('-i', 'ImportDefaultSpecifier', 'ImportNamespaceSpecifier',
'node_modules/@buxlabs/amd-to-es6/src/lib/getImportDeclaration.js');
also, adding rollup-plugin-amd to rollup_bundle means that some UMD formats will now fail to bundle as the plugin will try to convert the define within the UMD format. Because of this we limit this plugin to work on .ngfactory.js so that other files that may be UMD don't break the bundle.
internal/rollup/rollup.config.js:
amd({
include: '**/*.ngfactory.js',
}),
Using the tsc AMD format with the patched rollup-plugin-amd added to rollup_bundle we can generate .ngfactory files which work for devmode (ts_devserver and ts_web_test_suite) and prodmod (rollup_bundle).
Going forward
The above a not ideal and hacky. Beyond using AMD and having to uplevel to es6 with a patched rollup amd plugin, we also have to manually list the .ngfactory and .ngsummary files in the ts_devserver and ts_web_test_suite rules. For example:
ts_devserver(
name = "devserver",
data = [
"//src/images:image_assets",
],
entry_module = "abc_example/src/main.dev",
index_html = "index.html",
scripts = [
"@npm//node_modules/@angular/animations:bundles/animations.umd.js",
"@npm//node_modules/@angular/animations:bundles/animations-browser.umd.js",
"@npm//node_modules/@angular/forms:bundles/forms.umd.js",
"@npm//node_modules/@angular/common:bundles/common.umd.js",
"@npm//node_modules/@angular/common:bundles/common-http.umd.js",
"@npm//node_modules/@angular/core:bundles/core.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser-animations.umd.js",
"@npm//node_modules/@angular/material:bundles/material-core.umd.js",
"@npm//node_modules/@angular/material:bundles/material-button.umd.js",
"@npm//node_modules/@angular/material:bundles/material-card.umd.js",
"@npm//node_modules/@angular/material:bundles/material-form-field.umd.js",
"@npm//node_modules/@angular/material:bundles/material-icon.umd.js",
"@npm//node_modules/@angular/material:bundles/material-input.umd.js",
"@npm//node_modules/@angular/material:bundles/material-list.umd.js",
"@npm//node_modules/@angular/material:bundles/material-toolbar.umd.js",
"@npm//node_modules/@angular/material:bundles/material-divider.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-observers.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-collections.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-bidi.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-text-field.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-keycodes.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-coercion.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-platform.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-a11y.umd.js",
"@npm//node_modules/tslib:tslib.js",
":rxjs_umd_modules",
"@npm//node_modules/@angular/material:icon/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:card/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:toolbar/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:form-field/typings/index.ngfactory.js",
],
static_files = [
"//src/styles:main.css",
"@npm//node_modules/@angular/material:prebuilt-themes/deeppurple-amber.css",
"@npm//node_modules/zone.js:dist/zone.min.js",
],
deps = ["//src"],
)
ts_web_test_suite(
name = "test",
srcs = [
"@npm//node_modules/@angular/animations:bundles/animations.umd.js",
"@npm//node_modules/@angular/animations:bundles/animations-browser.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-observers.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-collections.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-bidi.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-text-field.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-keycodes.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-coercion.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-platform.umd.js",
"@npm//node_modules/@angular/cdk:bundles/cdk-a11y.umd.js",
"@npm//node_modules/@angular/common:bundles/common.umd.js",
"@npm//node_modules/@angular/common:bundles/common-http.umd.js",
"@npm//node_modules/@angular/compiler:bundles/compiler.umd.js",
"@npm//node_modules/@angular/compiler:bundles/compiler-testing.umd.js",
"@npm//node_modules/@angular/core:bundles/core.umd.js",
"@npm//node_modules/@angular/core:bundles/core-testing.umd.js",
"@npm//node_modules/@angular/forms:bundles/forms.umd.js",
"@npm//node_modules/@angular/material:bundles/material-core.umd.js",
"@npm//node_modules/@angular/material:bundles/material-button.umd.js",
"@npm//node_modules/@angular/material:bundles/material-card.umd.js",
"@npm//node_modules/@angular/material:bundles/material-form-field.umd.js",
"@npm//node_modules/@angular/material:bundles/material-icon.umd.js",
"@npm//node_modules/@angular/material:bundles/material-input.umd.js",
"@npm//node_modules/@angular/material:bundles/material-list.umd.js",
"@npm//node_modules/@angular/material:bundles/material-toolbar.umd.js",
"@npm//node_modules/@angular/material:bundles/material-divider.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser-testing.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser-animations.umd.js",
"@npm//node_modules/@angular/platform-browser-dynamic:bundles/platform-browser-dynamic.umd.js",
"@npm//node_modules/@angular/platform-browser-dynamic:bundles/platform-browser-dynamic-testing.umd.js",
"@npm//node_modules/@angular/forms:forms.ngsummary.js",
"@npm//node_modules/tslib:tslib.js",
# ngsummary files
"@npm//node_modules/@angular/common:common.ngsummary.js",
"@npm//node_modules/@angular/cdk:bidi/typings/index.ngsummary.js",
"@npm//node_modules/@angular/cdk:platform/typings/index.ngsummary.js",
"@npm//node_modules/@angular/cdk:observers/typings/index.ngsummary.js",
"@npm//node_modules/@angular/cdk:text-field/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:core/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:button/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:card/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:form-field/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:icon/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:input/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:divider/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:list/typings/index.ngsummary.js",
"@npm//node_modules/@angular/material:toolbar/typings/index.ngsummary.js",
# ngfactory files
"@npm//node_modules/@angular/material:core/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:button/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:card/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:form-field/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:icon/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:divider/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:list/typings/index.ngfactory.js",
"@npm//node_modules/@angular/material:toolbar/typings/index.ngfactory.js",
],
bootstrap = [
"@npm//node_modules/zone.js:dist/zone-testing-bundle.js",
"@npm//node_modules/reflect-metadata:Reflect.js",
],
deps = [
":test_lib",
"//src:rxjs_umd_modules",
],
)
Ideally, all of this would handled by Bazel with no postinstall step necessary and we would generate two different module formats for use in devmode and prodmode so we are not relying on a patched rollup amd plugin. @alexeagle and @kyle116 discussed a possible way to do this:
Basics:
- Let's say that
generate_build_files.jsdoesn't always produce afilegroup. It does some detection for the Angular Package Format and maybe for CJS formats too - In the case of APF it writes some new rule like apf_library or angular_package (to be named) which is a valid ts_library dep
- the angular_package rule takes the original npm-content as input, it runs ngc action internally, and produces a TreeArtifact output
- it might need to transform the package.json in some way so that we later choose the right paths to resolve the JS content
- angular_package rule could run ngc twice, as a devmode and prodmode, so it acts more like our typical library rules
- when the sources_aspect visits an angular_package rule it should come away with the UMD factories and the UMD bundles so a ts_devserver doesn't need any scripts - your ng_module dep on
@npm//@angular/coreis sufficient - for prodmode we'd get ES2015 factories that rollup understands
then we don't need the postinstall either
Activity
gregmagolan commentedon Mar 23, 2019
Example of this work-around in use: https://github.com/gregmagolan/abc-example
gregmagolan commentedon Mar 23, 2019
For reference, passing a tsc generated umd file through
rollup-plugin-amdcan result in a bundling error that looks like:Add rollup-plugin-amd to rollup_bundle to support bundling *.ngfactor…
alexeagle commentedon Apr 24, 2019
We still have to have module:amd in the angular-metadata.tsconfig.json but the BUILD files downstream no longer need to list the files. Considering this fixed. (With Ivy we can stop doing the compiler as a postinstall and just use ngcc like a non-bazel project)
Initial Toolchain Support
angular-automatic-lock-bot commentedon Sep 15, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.