Skip to content

Commit dec8967

Browse files
devversionjosephperrott
authored andcommitted
build: no longer load rxjs files individually (angular#14237)
* No longer loads all rxjs files individually when serving the dev-app. Now uses the UMD bundle which should speed up the initial loading of the dev-app with Gulp.
1 parent 81bf31e commit dec8967

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sass_generate_binaries("dev_app_scss", glob(["**/*.scss"], exclude = ["theme.scs
1313

1414
ng_module(
1515
name = "dev-app",
16-
srcs = glob(["**/*.ts"], exclude = ["system-config.ts"]),
16+
srcs = glob(["**/*.ts"], exclude = ["system-config.ts", "system-rxjs-operators.ts"]),
1717
assets = glob(["**/*.html"]) + [":dev_app_scss", ":theme"],
1818
deps = [
1919
"@angular//packages/common",

src/dev-app/system-config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ System.config({
1515
'node:*': 'node_modules/*'
1616
},
1717
map: {
18-
'rxjs': 'node:rxjs',
1918
'main': 'main.js',
2019
'tslib': 'node:tslib/tslib.js',
2120
'moment': 'node:moment/min/moment-with-locales.min.js',
2221

22+
'rxjs': 'node_modules/rxjs/bundles/rxjs.umd.min.js',
23+
'rxjs/operators': 'system-rxjs-operators.js',
24+
2325
// Angular specific mappings.
2426
'@angular/core': 'node:@angular/core/bundles/core.umd.js',
2527
'@angular/common': 'node:@angular/common/bundles/common.umd.js',
@@ -102,10 +104,6 @@ System.config({
102104
'@angular/material/tree': 'dist/packages/material/tree/index.js',
103105
},
104106
packages: {
105-
// Thirdparty barrels.
106-
'rxjs': {main: 'index'},
107-
'rxjs/operators': {main: 'index'},
108-
109107
// Set the default extension for the root package, because otherwise the dev-app can't
110108
// be built within the production mode. Due to missing file extensions.
111109
'.': {

src/dev-app/system-rxjs-operators.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
10+
// Workaround for an issue where RxJS cannot be used with UMD bundles only. This is because
11+
// rxjs only ships one UMD bundle and expects everyone to only use the named "rxjs" AMD module.
12+
// Since our code internally loads operators from "rxjs/operators/index", we need to make sure
13+
// that we re-export all operators from the UMD module. This is a small trade-off for not loading
14+
// all rxjs files individually.
15+
16+
declare const define: {
17+
(deps: string[], factory: (...deps: any[]) => void): void;
18+
amd: boolean;
19+
};
20+
21+
if (typeof define === 'function' && define.amd) {
22+
define(['exports', 'rxjs'], (exports: any, rxjs: any) => {
23+
// Re-export all operators in this AMD module.
24+
Object.assign(exports, rxjs.operators);
25+
});
26+
}

src/dev-app/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"files": [
4242
"./typings.d.ts",
4343
"./dev-app-module.ts",
44+
"./system-rxjs-operators.ts",
4445
"./system-config.ts",
4546
"./main.ts"
4647
]

0 commit comments

Comments
 (0)