-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@ngtools/webpack): replace server bootstrap code (#5194)
- Loading branch information
1 parent
e619df1
commit ad026ef
Showing
15 changed files
with
274 additions
and
4 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
5 changes: 5 additions & 0 deletions
5
tests/e2e/assets/webpack/test-server-app/app/app.component.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,5 @@ | ||
<div> | ||
<h1>hello world</h1> | ||
<a [routerLink]="['lazy']">lazy</a> | ||
<router-outlet></router-outlet> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
tests/e2e/assets/webpack/test-server-app/app/app.component.scss
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,3 @@ | ||
:host { | ||
background-color: blue; | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/e2e/assets/webpack/test-server-app/app/app.component.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Component, ViewEncapsulation} from '@angular/core'; | ||
import {MyInjectable} from './injectable'; | ||
|
||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class AppComponent { | ||
constructor(public inj: MyInjectable) { | ||
console.log(inj); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/e2e/assets/webpack/test-server-app/app/app.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NgModule, Component } from '@angular/core'; | ||
import { ServerModule } from '@angular/platform-server'; | ||
import { RouterModule } from '@angular/router'; | ||
import { AppComponent } from './app.component'; | ||
|
||
@Component({ | ||
selector: 'home-view', | ||
template: 'home!' | ||
}) | ||
export class HomeView {} | ||
|
||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent, | ||
HomeView | ||
], | ||
imports: [ | ||
ServerModule, | ||
RouterModule.forRoot([ | ||
{path: 'lazy', loadChildren: './lazy.module#LazyModule'}, | ||
{path: '', component: HomeView} | ||
]) | ||
], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } |
20 changes: 20 additions & 0 deletions
20
tests/e2e/assets/webpack/test-server-app/app/feature/feature.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {NgModule, Component} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'feature-component', | ||
template: 'foo.html' | ||
}) | ||
export class FeatureComponent {} | ||
|
||
@NgModule({ | ||
declarations: [ | ||
FeatureComponent | ||
], | ||
imports: [ | ||
RouterModule.forChild([ | ||
{ path: '', component: FeatureComponent} | ||
]) | ||
] | ||
}) | ||
export class FeatureModule {} |
23 changes: 23 additions & 0 deletions
23
tests/e2e/assets/webpack/test-server-app/app/feature/lazy-feature.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {NgModule, Component} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
import {HttpModule, Http} from '@angular/http'; | ||
|
||
@Component({ | ||
selector: 'lazy-feature-comp', | ||
template: 'lazy feature!' | ||
}) | ||
export class LazyFeatureComponent {} | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild([ | ||
{path: '', component: LazyFeatureComponent, pathMatch: 'full'}, | ||
{path: 'feature', loadChildren: './feature.module#FeatureModule'} | ||
]), | ||
HttpModule | ||
], | ||
declarations: [LazyFeatureComponent] | ||
}) | ||
export class LazyFeatureModule { | ||
constructor(http: Http) {} | ||
} |
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 {Injectable, Inject, ViewContainerRef} from '@angular/core'; | ||
import {DOCUMENT} from '@angular/platform-browser'; | ||
|
||
|
||
@Injectable() | ||
export class MyInjectable { | ||
constructor(public viewContainer: ViewContainerRef, @Inject(DOCUMENT) public doc) {} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/e2e/assets/webpack/test-server-app/app/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {NgModule, Component} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
import {HttpModule, Http} from '@angular/http'; | ||
|
||
@Component({ | ||
selector: 'lazy-comp', | ||
template: 'lazy!' | ||
}) | ||
export class LazyComponent {} | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild([ | ||
{path: '', component: LazyComponent, pathMatch: 'full'}, | ||
{path: 'feature', loadChildren: './feature/feature.module#FeatureModule'}, | ||
{path: 'lazy-feature', loadChildren: './feature/lazy-feature.module#LazyFeatureModule'} | ||
]), | ||
HttpModule | ||
], | ||
declarations: [LazyComponent] | ||
}) | ||
export class LazyModule { | ||
constructor(http: Http) {} | ||
} | ||
|
||
export class SecondModule {} |
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,5 @@ | ||
import 'core-js/es7/reflect'; | ||
import {platformDynamicServer} from '@angular/platform-server'; | ||
import {AppModule} from './app.module'; | ||
|
||
platformDynamicServer().bootstrapModule(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,12 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
<base href=""> | ||
</head> | ||
<body> | ||
<app-root></app-root> | ||
<script src="node_modules/zone.js/dist/zone.js"></script> | ||
<script src="dist/app.main.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,28 @@ | ||
{ | ||
"name": "test", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@angular/animations": "^4.0.0", | ||
"@angular/common": "^4.0.0", | ||
"@angular/compiler": "^4.0.0", | ||
"@angular/compiler-cli": "^4.0.0", | ||
"@angular/core": "^4.0.0", | ||
"@angular/http": "^4.0.0", | ||
"@angular/platform-browser": "^4.0.0", | ||
"@angular/platform-browser-dynamic": "^4.0.0", | ||
"@angular/platform-server": "^4.0.0", | ||
"@angular/router": "^4.0.0", | ||
"@ngtools/webpack": "0.0.0", | ||
"core-js": "^2.4.1", | ||
"rxjs": "^5.3.1", | ||
"zone.js": "^0.8.10" | ||
}, | ||
"devDependencies": { | ||
"node-sass": "^4.5.0", | ||
"performance-now": "^0.2.0", | ||
"raw-loader": "^0.5.1", | ||
"sass-loader": "^6.0.3", | ||
"typescript": "^2.3.2", | ||
"webpack": "2.2.1" | ||
} | ||
} |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "", | ||
"module": "es2015", | ||
"moduleResolution": "node", | ||
"target": "es5", | ||
"noImplicitAny": false, | ||
"sourceMap": true, | ||
"mapRoot": "", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"lib": [ | ||
"es2016", | ||
"dom" | ||
], | ||
"outDir": "lib", | ||
"skipLibCheck": true, | ||
"rootDir": "." | ||
}, | ||
"angularCompilerOptions": { | ||
"genDir": "./app/ngfactory", | ||
"entryModule": "app/app.module#AppModule" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/e2e/assets/webpack/test-server-app/webpack.config.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,30 @@ | ||
const ngToolsWebpack = require('@ngtools/webpack'); | ||
|
||
module.exports = { | ||
resolve: { | ||
extensions: ['.ts', '.js'] | ||
}, | ||
target: 'web', | ||
entry: './app/main.ts', | ||
output: { | ||
path: './dist', | ||
publicPath: 'dist/', | ||
filename: 'app.main.js' | ||
}, | ||
plugins: [ | ||
new ngToolsWebpack.AotPlugin({ | ||
tsConfigPath: './tsconfig.json' | ||
}) | ||
], | ||
module: { | ||
loaders: [ | ||
{ test: /\.scss$/, loaders: ['raw-loader', 'sass-loader'] }, | ||
{ test: /\.css$/, loader: 'raw-loader' }, | ||
{ test: /\.html$/, loader: 'raw-loader' }, | ||
{ test: /\.ts$/, loader: '@ngtools/webpack' } | ||
] | ||
}, | ||
devServer: { | ||
historyApiFallback: 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,20 @@ | ||
import {normalize} from 'path'; | ||
import {createProjectFromAsset} from '../../../utils/assets'; | ||
import {exec} from '../../../utils/process'; | ||
import {expectFileToMatch} from '../../../utils/fs'; | ||
|
||
|
||
export default function(skipCleaning: () => void) { | ||
return Promise.resolve() | ||
.then(() => createProjectFromAsset('webpack/test-server-app')) | ||
.then(() => exec(normalize('node_modules/.bin/webpack'))) | ||
.then(() => expectFileToMatch('dist/app.main.js', | ||
new RegExp('.bootstrapModuleFactory')) | ||
.then(() => expectFileToMatch('dist/app.main.js', | ||
new RegExp('MyInjectable.ctorParameters = .*' | ||
+ 'type: .*ViewContainerRef.*' | ||
+ 'type: undefined, decorators.*Inject.*args: .*DOCUMENT.*')) | ||
.then(() => expectFileToMatch('dist/app.main.js', | ||
new RegExp('AppComponent.ctorParameters = .*MyInjectable')) | ||
.then(() => skipCleaning()); | ||
} |