Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

docs(systemjs.web): can create a default for missing AppModule.ts #2827

Merged
merged 1 commit into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions public/docs/_examples/_boilerplate/systemjs.config.web.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
// Complete copy of compiler options in standard tsconfig.json
// Copy of compiler options in standard tsconfig.json
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"../../node_modules/@types/"
]
"suppressImplicitAnyIndexErrors": true
},
meta: {
'typescript': {
Expand Down Expand Up @@ -85,14 +81,15 @@

// Bootstrap the `AppModule`(skip the `app/main.ts` that normally does this)
function bootstrap() {
console.log('Auto-bootstrapping');

// Stub out `app/main.ts` so System.import('app') doesn't fail if called in the index.html
System.set(System.normalizeSync('app/main.ts'), System.newModule({ }));

// bootstrap and launch the app (equivalent to standard main.ts)
Promise.all([
System.import('@angular/platform-browser-dynamic'),
System.import('app/app.module')
getAppModule()
])
.then(function (imports) {
var platform = imports[0];
Expand All @@ -102,4 +99,39 @@
.catch(function(err){ console.error(err); });
}

// Import AppModule or make the default AppModule if there isn't one
// returns a promise for the AppModule
function getAppModule() {
if (global.noAppModule) {
return makeAppModule();
}
return System.import('app/app.module').catch(makeAppModule)
}

function makeAppModule() {
console.log('No AppModule; making a bare-bones, default AppModule');

return Promise.all([
System.import('@angular/core'),
System.import('@angular/platform-browser'),
System.import('app/app.component')
])
.then(function (imports) {

var core = imports[0];
var browser = imports[1];
var appComp = imports[2].AppComponent;

var AppModule = function() {}

AppModule.annotations = [
new core.NgModule({
imports: [ browser.BrowserModule ],
declarations: [ appComp ],
bootstrap: [ appComp ]
})
]
return {AppModule: AppModule};
})
}
})(this);
46 changes: 39 additions & 7 deletions public/docs/_examples/_boilerplate/systemjs.config.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
// Complete copy of compiler options in standard tsconfig.json
// Copy of compiler options in standard tsconfig.json
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"../../node_modules/@types/"
]
"suppressImplicitAnyIndexErrors": true
},
meta: {
'typescript': {
Expand Down Expand Up @@ -72,14 +68,15 @@

// Bootstrap the `AppModule`(skip the `app/main.ts` that normally does this)
function bootstrap() {
console.log('Auto-bootstrapping');

// Stub out `app/main.ts` so System.import('app') doesn't fail if called in the index.html
System.set(System.normalizeSync('app/main.ts'), System.newModule({ }));

// bootstrap and launch the app (equivalent to standard main.ts)
Promise.all([
System.import('@angular/platform-browser-dynamic'),
System.import('app/app.module')
getAppModule()
])
.then(function (imports) {
var platform = imports[0];
Expand All @@ -89,4 +86,39 @@
.catch(function(err){ console.error(err); });
}

// Import AppModule or make the default AppModule if there isn't one
// returns a promise for the AppModule
function getAppModule() {
if (global.noAppModule) {
return makeAppModule();
}
return System.import('app/app.module').catch(makeAppModule)
}

function makeAppModule() {
console.log('No AppModule; making a bare-bones, default AppModule');

return Promise.all([
System.import('@angular/core'),
System.import('@angular/platform-browser'),
System.import('app/app.component')
])
.then(function (imports) {

var core = imports[0];
var browser = imports[1];
var appComp = imports[2].AppComponent;

var AppModule = function() {}

AppModule.annotations = [
new core.NgModule({
imports: [ browser.BrowserModule ],
declarations: [ appComp ],
bootstrap: [ appComp ]
})
]
return {AppModule: AppModule};
})
}
})(this);