Skip to content

Commit 892caa7

Browse files
committed
feat(platform-browser-dynamic): export JitCompilerFactory
Fixes #20125
1 parent 2a9d2ba commit 892caa7

17 files changed

Lines changed: 280 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { AppPage } from './app.po';
2+
3+
describe('dynamic-compiler App', () => {
4+
let page: AppPage;
5+
6+
beforeEach(() => {
7+
page = new AppPage();
8+
});
9+
10+
it('should display welcome message', () => {
11+
page.navigateTo();
12+
expect(page.getParagraphText()).toEqual('Hello world!');
13+
});
14+
15+
it('should display lazy-loaded component', () => {
16+
page.navigateTo();
17+
expect(page.getLazyLoadedText()).toEqual('Lazy-loaded component!');
18+
});
19+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {browser, by, element, protractor} from 'protractor';
2+
3+
export class AppPage {
4+
navigateTo() {
5+
return browser.get('/');
6+
}
7+
8+
getParagraphText() {
9+
return element(by.css('app-root h1')).getText();
10+
}
11+
12+
getLazyLoadedText() {
13+
const el = element(by.css('app-root lazy-component'));
14+
return browser.wait(protractor.ExpectedConditions.presenceOf(el)).then(() => el.getText(), err => el.getText());
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"open": false,
3+
"logLevel": "silent",
4+
"port": 8080,
5+
"server": {
6+
"baseDir": ".",
7+
"routes": {
8+
"/dist": "dist",
9+
"/node_modules": "node_modules"
10+
},
11+
"middleware": {
12+
"0": null
13+
}
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports.config = {
2+
specs: [
3+
'../dist/e2e/*.e2e-spec.js'
4+
],
5+
capabilities: {
6+
browserName: 'chrome',
7+
chromeOptions: {
8+
args: ['--no-sandbox'],
9+
binary: process.env.CHROME_BIN,
10+
}
11+
},
12+
directConnect: true,
13+
baseUrl: 'http://localhost:8080/',
14+
framework: 'jasmine',
15+
useAllAngular2AppRoots: true
16+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "../dist/e2e",
4+
"types": ["jasmine"],
5+
"skipLibCheck": true
6+
}
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<app-root></app-root>
9+
<script src="/node_modules/zone.js/dist/zone.js"></script>
10+
<script src="/node_modules/reflect-metadata/Reflect.js"></script>
11+
<script src="/node_modules/systemjs/dist/system.js"></script>
12+
<script src="/dist/bundle.js"></script>
13+
</body>
14+
</html>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "dynamic-compiler",
3+
"version": "0.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"build": "npm run clean && npm run ngc && npm run rollup && npm run rollup:lazy && npm run es5 && npm run es5:lazy",
7+
"clean": "rm -rf dist",
8+
"es5": "tsc --target es5 --skipLibCheck --allowJs dist/bundle.es2015.js --out dist/bundle.js",
9+
"es5:lazy": "tsc --target es5 --skipLibCheck --allowJs dist/lazy.bundle.es2015.js --out dist/lazy.bundle.js",
10+
"ngc": "ngc -p tsconfig.json",
11+
"rollup": "rollup -f iife -c rollup.config.js -o dist/bundle.es2015.js",
12+
"rollup:lazy": "rollup -f cjs -c rollup.lazy.config.js -o dist/lazy.bundle.es2015.js",
13+
"postinstall": "webdriver-manager update --gecko false",
14+
"preprotractor": "tsc -p e2e",
15+
"protractor": "protractor e2e/protractor.config.js",
16+
"serve": "lite-server -c e2e/browser.config.json",
17+
"test": "npm run build && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first"
18+
},
19+
"license": "MIT",
20+
"devDependencies": {
21+
"@types/jasmine": "file:../../node_modules/@types/jasmine",
22+
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
23+
"concurrently": "3.4.0",
24+
"lite-server": "2.2.2",
25+
"protractor": "file:../../node_modules/protractor",
26+
"rollup": "file:../../node_modules/rollup",
27+
"rollup-plugin-commonjs": "file:../../node_modules/rollup-plugin-commonjs",
28+
"rollup-plugin-node-resolve": "file:../../node_modules/rollup-plugin-node-resolve",
29+
"typescript": "file:../../node_modules/typescript"
30+
},
31+
"dependencies": {
32+
"@angular/animations": "file:../../dist/packages-dist/animations",
33+
"@angular/common": "file:../../dist/packages-dist/common",
34+
"@angular/compiler": "file:../../dist/packages-dist/compiler",
35+
"@angular/core": "file:../../dist/packages-dist/core",
36+
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
37+
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
38+
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
39+
"core-js": "file:../../node_modules/core-js",
40+
"rxjs": "file:../../node_modules/rxjs",
41+
"systemjs": "file:../../node_modules/systemjs",
42+
"zone.js": "file:../../node_modules/zone.js"
43+
}
44+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import nodeResolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
4+
export default {
5+
entry: 'dist/src/main.js',
6+
sourceMap: true,
7+
treeshake: true,
8+
moduleName: 'main',
9+
plugins: [
10+
commonjs({
11+
include: 'node_modules/**'
12+
}),
13+
nodeResolve({
14+
jsnext: true, main: true, module: true
15+
})
16+
]
17+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import nodeResolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
4+
// a real app should make a common bundle for libraries instead of bundling them
5+
// in both the main module & the lazy module, but we don't care about size here
6+
export default {
7+
entry: 'dist/src/lazy.module.js',
8+
sourceMap: true,
9+
treeshake: true,
10+
moduleName: 'lazy',
11+
plugins: [
12+
commonjs({
13+
include: 'node_modules/**'
14+
}),
15+
nodeResolve({
16+
jsnext: true, main: true, module: true
17+
})
18+
]
19+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {AfterViewInit, Compiler, Component, ViewChild, ViewContainerRef} from '@angular/core';
2+
3+
declare var System: any;
4+
5+
@Component({
6+
selector: 'app-root',
7+
template: `
8+
<h1>Hello world!</h1>
9+
<div #vc></div>
10+
`,
11+
})
12+
export class AppComponent implements AfterViewInit {
13+
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef;
14+
15+
constructor(private compiler: Compiler) {
16+
}
17+
18+
ngAfterViewInit() {
19+
System.import('./dist/lazy.bundle.js').then((module: any) => {
20+
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule)
21+
.then((compiled) => {
22+
const factory = compiled.componentFactories[0];
23+
this.container.createComponent(factory);
24+
});
25+
});
26+
}
27+
}

0 commit comments

Comments
 (0)