forked from angular/angular
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform-browser-dynamic): export
JitCompilerFactory
(angular#…
…20478) Fixes angular#20125 PR Close angular#20478
- Loading branch information
Showing
17 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AppPage } from './app.po'; | ||
|
||
describe('dynamic-compiler App', () => { | ||
let page: AppPage; | ||
|
||
beforeEach(() => { | ||
page = new AppPage(); | ||
}); | ||
|
||
it('should display welcome message', () => { | ||
page.navigateTo(); | ||
expect(page.getParagraphText()).toEqual('Hello world!'); | ||
}); | ||
|
||
it('should display lazy-loaded component', () => { | ||
page.navigateTo(); | ||
expect(page.getLazyLoadedText()).toEqual('Lazy-loaded component!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {browser, by, element, protractor} from 'protractor'; | ||
|
||
export class AppPage { | ||
navigateTo() { | ||
return browser.get('/'); | ||
} | ||
|
||
getParagraphText() { | ||
return element(by.css('app-root h1')).getText(); | ||
} | ||
|
||
getLazyLoadedText() { | ||
const el = element(by.css('app-root lazy-component')); | ||
return browser.wait(protractor.ExpectedConditions.presenceOf(el)).then(() => el.getText(), err => el.getText()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"open": false, | ||
"logLevel": "silent", | ||
"port": 8080, | ||
"server": { | ||
"baseDir": ".", | ||
"routes": { | ||
"/dist": "dist", | ||
"/node_modules": "node_modules" | ||
}, | ||
"middleware": { | ||
"0": null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
exports.config = { | ||
specs: [ | ||
'../dist/e2e/*.e2e-spec.js' | ||
], | ||
capabilities: { | ||
browserName: 'chrome', | ||
chromeOptions: { | ||
args: ['--no-sandbox'], | ||
binary: process.env.CHROME_BIN, | ||
} | ||
}, | ||
directConnect: true, | ||
baseUrl: 'http://localhost:8080/', | ||
framework: 'jasmine', | ||
useAllAngular2AppRoots: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "../dist/e2e", | ||
"types": ["jasmine"], | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
<app-root></app-root> | ||
<script src="/node_modules/zone.js/dist/zone.js"></script> | ||
<script src="/node_modules/reflect-metadata/Reflect.js"></script> | ||
<script src="/node_modules/systemjs/dist/system.js"></script> | ||
<script src="/dist/bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "dynamic-compiler", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "npm run clean && npm run ngc && npm run rollup && npm run rollup:lazy && npm run es5 && npm run es5:lazy", | ||
"clean": "rm -rf dist", | ||
"es5": "tsc --target es5 --skipLibCheck --allowJs dist/bundle.es2015.js --out dist/bundle.js", | ||
"es5:lazy": "tsc --target es5 --skipLibCheck --allowJs dist/lazy.bundle.es2015.js --out dist/lazy.bundle.js", | ||
"ngc": "ngc -p tsconfig.json", | ||
"rollup": "rollup -f iife -c rollup.config.js -o dist/bundle.es2015.js", | ||
"rollup:lazy": "rollup -f cjs -c rollup.lazy.config.js -o dist/lazy.bundle.es2015.js", | ||
"postinstall": "webdriver-manager update --gecko false", | ||
"preprotractor": "tsc -p e2e", | ||
"protractor": "protractor e2e/protractor.config.js", | ||
"serve": "lite-server -c e2e/browser.config.json", | ||
"test": "npm run build && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/jasmine": "file:../../node_modules/@types/jasmine", | ||
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", | ||
"concurrently": "3.4.0", | ||
"lite-server": "2.2.2", | ||
"protractor": "file:../../node_modules/protractor", | ||
"rollup": "file:../../node_modules/rollup", | ||
"rollup-plugin-commonjs": "file:../../node_modules/rollup-plugin-commonjs", | ||
"rollup-plugin-node-resolve": "file:../../node_modules/rollup-plugin-node-resolve", | ||
"typescript": "file:../../node_modules/typescript" | ||
}, | ||
"dependencies": { | ||
"@angular/animations": "file:../../dist/packages-dist/animations", | ||
"@angular/common": "file:../../dist/packages-dist/common", | ||
"@angular/compiler": "file:../../dist/packages-dist/compiler", | ||
"@angular/core": "file:../../dist/packages-dist/core", | ||
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", | ||
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", | ||
"@angular/platform-server": "file:../../dist/packages-dist/platform-server", | ||
"core-js": "file:../../node_modules/core-js", | ||
"rxjs": "file:../../node_modules/rxjs", | ||
"systemjs": "file:../../node_modules/systemjs", | ||
"zone.js": "file:../../node_modules/zone.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
|
||
export default { | ||
entry: 'dist/src/main.js', | ||
sourceMap: true, | ||
treeshake: true, | ||
moduleName: 'main', | ||
plugins: [ | ||
commonjs({ | ||
include: 'node_modules/**' | ||
}), | ||
nodeResolve({ | ||
jsnext: true, main: true, module: true | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
|
||
// a real app should make a common bundle for libraries instead of bundling them | ||
// in both the main module & the lazy module, but we don't care about size here | ||
export default { | ||
entry: 'dist/src/lazy.module.js', | ||
sourceMap: true, | ||
treeshake: true, | ||
moduleName: 'lazy', | ||
plugins: [ | ||
commonjs({ | ||
include: 'node_modules/**' | ||
}), | ||
nodeResolve({ | ||
jsnext: true, main: true, module: true | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {AfterViewInit, Compiler, Component, ViewChild, ViewContainerRef} from '@angular/core'; | ||
|
||
declare var System: any; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<h1>Hello world!</h1> | ||
<div #vc></div> | ||
`, | ||
}) | ||
export class AppComponent implements AfterViewInit { | ||
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef; | ||
|
||
constructor(private compiler: Compiler) { | ||
} | ||
|
||
ngAfterViewInit() { | ||
System.import('./dist/lazy.bundle.js').then((module: any) => { | ||
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule) | ||
.then((compiled) => { | ||
const factory = compiled.componentFactories[0]; | ||
this.container.createComponent(factory); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {Compiler, COMPILER_OPTIONS, CompilerFactory, NgModule} from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import {JitCompilerFactory} from '@angular/platform-browser-dynamic'; | ||
|
||
import { AppComponent } from './app.component'; | ||
|
||
export function createCompiler(compilerFactory: CompilerFactory) { | ||
return compilerFactory.createCompiler(); | ||
} | ||
|
||
@NgModule({ | ||
imports: [BrowserModule], | ||
bootstrap: [AppComponent], | ||
declarations: [AppComponent], | ||
providers: [ | ||
{provide: COMPILER_OPTIONS, useValue: {}, multi: true}, | ||
{provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]}, | ||
{provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory]} | ||
] | ||
}) | ||
export class AppModule {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {NgModule} from "@angular/core"; | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'lazy-component', | ||
template: 'Lazy-loaded component!' | ||
}) | ||
export class LazyComponent { | ||
constructor() { | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [LazyComponent] | ||
}) | ||
export class LazyModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { enableProdMode } from '@angular/core'; | ||
import { platformBrowser } from '@angular/platform-browser'; | ||
|
||
import { AppModuleNgFactory } from './app.module.ngfactory'; | ||
|
||
enableProdMode(); | ||
|
||
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"module": "es2015", | ||
"moduleResolution": "node", | ||
"declaration": false, | ||
"removeComments": true, | ||
"noLib": false, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"lib": ["es6", "es2015", "dom"], | ||
"sourceMap": true, | ||
"pretty": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitUseStrict": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"outDir": "./dist", | ||
"types": [ | ||
] | ||
}, | ||
"files": [ | ||
"src/main.ts", | ||
"src/lazy.module.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tools/public_api_guard/platform-browser-dynamic/platform-browser-dynamic.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters