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

Commit f2daab7

Browse files
authored
Merge pull request #2827 from IdeaBlade/systemjs-create-appmodule
docs(systemjs.web): can create a default for missing AppModule.ts
2 parents 1fe2083 + ed3101a commit f2daab7

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

public/docs/_examples/_boilerplate/systemjs.config.web.build.js

+39-7
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
1212
transpiler: 'ts',
1313
typescriptOptions: {
14-
// Complete copy of compiler options in standard tsconfig.json
14+
// Copy of compiler options in standard tsconfig.json
1515
"target": "es5",
1616
"module": "commonjs",
1717
"moduleResolution": "node",
1818
"sourceMap": true,
1919
"emitDecoratorMetadata": true,
2020
"experimentalDecorators": true,
21-
"removeComments": false,
2221
"noImplicitAny": true,
23-
"suppressImplicitAnyIndexErrors": true,
24-
"typeRoots": [
25-
"../../node_modules/@types/"
26-
]
22+
"suppressImplicitAnyIndexErrors": true
2723
},
2824
meta: {
2925
'typescript': {
@@ -85,14 +81,15 @@
8581

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

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

9289
// bootstrap and launch the app (equivalent to standard main.ts)
9390
Promise.all([
9491
System.import('@angular/platform-browser-dynamic'),
95-
System.import('app/app.module')
92+
getAppModule()
9693
])
9794
.then(function (imports) {
9895
var platform = imports[0];
@@ -102,4 +99,39 @@
10299
.catch(function(err){ console.error(err); });
103100
}
104101

102+
// Import AppModule or make the default AppModule if there isn't one
103+
// returns a promise for the AppModule
104+
function getAppModule() {
105+
if (global.noAppModule) {
106+
return makeAppModule();
107+
}
108+
return System.import('app/app.module').catch(makeAppModule)
109+
}
110+
111+
function makeAppModule() {
112+
console.log('No AppModule; making a bare-bones, default AppModule');
113+
114+
return Promise.all([
115+
System.import('@angular/core'),
116+
System.import('@angular/platform-browser'),
117+
System.import('app/app.component')
118+
])
119+
.then(function (imports) {
120+
121+
var core = imports[0];
122+
var browser = imports[1];
123+
var appComp = imports[2].AppComponent;
124+
125+
var AppModule = function() {}
126+
127+
AppModule.annotations = [
128+
new core.NgModule({
129+
imports: [ browser.BrowserModule ],
130+
declarations: [ appComp ],
131+
bootstrap: [ appComp ]
132+
})
133+
]
134+
return {AppModule: AppModule};
135+
})
136+
}
105137
})(this);

public/docs/_examples/_boilerplate/systemjs.config.web.js

+39-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@
99
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
1010
transpiler: 'ts',
1111
typescriptOptions: {
12-
// Complete copy of compiler options in standard tsconfig.json
12+
// Copy of compiler options in standard tsconfig.json
1313
"target": "es5",
1414
"module": "commonjs",
1515
"moduleResolution": "node",
1616
"sourceMap": true,
1717
"emitDecoratorMetadata": true,
1818
"experimentalDecorators": true,
19-
"removeComments": false,
2019
"noImplicitAny": true,
21-
"suppressImplicitAnyIndexErrors": true,
22-
"typeRoots": [
23-
"../../node_modules/@types/"
24-
]
20+
"suppressImplicitAnyIndexErrors": true
2521
},
2622
meta: {
2723
'typescript': {
@@ -72,14 +68,15 @@
7268

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

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

7976
// bootstrap and launch the app (equivalent to standard main.ts)
8077
Promise.all([
8178
System.import('@angular/platform-browser-dynamic'),
82-
System.import('app/app.module')
79+
getAppModule()
8380
])
8481
.then(function (imports) {
8582
var platform = imports[0];
@@ -89,4 +86,39 @@
8986
.catch(function(err){ console.error(err); });
9087
}
9188

89+
// Import AppModule or make the default AppModule if there isn't one
90+
// returns a promise for the AppModule
91+
function getAppModule() {
92+
if (global.noAppModule) {
93+
return makeAppModule();
94+
}
95+
return System.import('app/app.module').catch(makeAppModule)
96+
}
97+
98+
function makeAppModule() {
99+
console.log('No AppModule; making a bare-bones, default AppModule');
100+
101+
return Promise.all([
102+
System.import('@angular/core'),
103+
System.import('@angular/platform-browser'),
104+
System.import('app/app.component')
105+
])
106+
.then(function (imports) {
107+
108+
var core = imports[0];
109+
var browser = imports[1];
110+
var appComp = imports[2].AppComponent;
111+
112+
var AppModule = function() {}
113+
114+
AppModule.annotations = [
115+
new core.NgModule({
116+
imports: [ browser.BrowserModule ],
117+
declarations: [ appComp ],
118+
bootstrap: [ appComp ]
119+
})
120+
]
121+
return {AppModule: AppModule};
122+
})
123+
}
92124
})(this);

0 commit comments

Comments
 (0)