diff --git a/gulpfile.js b/gulpfile.js index a30abd0fc7..82583e76bb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -86,6 +86,7 @@ var _excludeMatchers = _excludePatterns.map(function(excludePattern){ var _exampleBoilerplateFiles = [ 'src/styles.css', 'src/systemjs.config.js', + 'src/systemjs-angular-loader.js', 'src/tsconfig.json', 'bs-config.json', 'bs-config.e2e.json', diff --git a/public/docs/_examples/.gitignore b/public/docs/_examples/.gitignore index eedd04da43..3fb5ae8562 100644 --- a/public/docs/_examples/.gitignore +++ b/public/docs/_examples/.gitignore @@ -1,6 +1,7 @@ # _boilerplate files !_boilerplate/* */*/src/styles.css +*/*/src/systemjs-angular-loader.js */*/src/systemjs.config.js */*/src/tsconfig.json */*/bs-config.e2e.json diff --git a/public/docs/_examples/_boilerplate/src/systemjs-angular-loader.js b/public/docs/_examples/_boilerplate/src/systemjs-angular-loader.js new file mode 100644 index 0000000000..5aa9a31411 --- /dev/null +++ b/public/docs/_examples/_boilerplate/src/systemjs-angular-loader.js @@ -0,0 +1,43 @@ +var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm; +var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g; +var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g; + +module.exports.translate = function(load){ + + var url = new URL(load.address); + + var basePathParts = url.pathname.split('/'); + + if (url.href.indexOf('plnkr') != -1) { + basePathParts.shift(); + basePathParts.shift(); + } + + basePathParts.pop(); + var basePath = basePathParts.join('/'); + load.source = load.source + .replace(templateUrlRegex, function(match, quote, url){ + let resolvedUrl = url; + + if (url.startsWith('.')) { + resolvedUrl = basePath + url.substr(1); + } + + return `templateUrl: '${resolvedUrl}'`; + }) + .replace(stylesRegex, function(match, relativeUrls) { + var urls = []; + + while ((match = stringRegex.exec(relativeUrls)) !== null) { + if (match[2].startsWith('.')) { + urls.push(`'${basePath.substr(1)}${match[2].substr(1)}'`); + } else { + urls.push(`'${match[2]}'`); + } + } + + return "styleUrls: [" + urls.join(', ') + "]"; + }); + + return load; +}; diff --git a/public/docs/_examples/_boilerplate/src/systemjs.config.js b/public/docs/_examples/_boilerplate/src/systemjs.config.js index 5fa7e9c24f..9c2883b953 100644 --- a/public/docs/_examples/_boilerplate/src/systemjs.config.js +++ b/public/docs/_examples/_boilerplate/src/systemjs.config.js @@ -11,7 +11,7 @@ // map tells the System loader where to look for things map: { // our app is within the app folder - app: 'app', + 'app': 'app', // angular bundles '@angular/core': 'npm:@angular/core/bundles/core.umd.js', @@ -32,7 +32,12 @@ packages: { app: { main: './main.js', - defaultExtension: 'js' + defaultExtension: 'js', + meta: { + './*.js': { + loader: 'systemjs-angular-loader.js' + } + } }, rxjs: { defaultExtension: 'js' diff --git a/public/docs/_examples/_boilerplate/src/systemjs.config.web.build.js b/public/docs/_examples/_boilerplate/src/systemjs.config.web.build.js index c27642ce02..35fd6ed6ad 100644 --- a/public/docs/_examples/_boilerplate/src/systemjs.config.web.build.js +++ b/public/docs/_examples/_boilerplate/src/systemjs.config.web.build.js @@ -34,8 +34,9 @@ }, // map tells the System loader where to look for things map: { + 'ng-loader': './systemjs-angular-loader.js', // our app is within the app folder - app: 'app', + 'app': 'app', // angular bundles '@angular/core': 'ng:core-builds/master/bundles/core.umd.js', @@ -71,7 +72,12 @@ packages: { app: { main: './main.ts', - defaultExtension: 'ts' + defaultExtension: 'ts', + meta: { + './*.ts': { + loader: 'ng-loader' + } + } }, rxjs: { defaultExtension: 'js' diff --git a/public/docs/_examples/_boilerplate/src/systemjs.config.web.js b/public/docs/_examples/_boilerplate/src/systemjs.config.web.js index dc0234a172..91cfc03627 100644 --- a/public/docs/_examples/_boilerplate/src/systemjs.config.web.js +++ b/public/docs/_examples/_boilerplate/src/systemjs.config.web.js @@ -31,8 +31,9 @@ }, // map tells the System loader where to look for things map: { + 'ng-loader': './systemjs-angular-loader.js', // our app is within the app folder - app: 'app', + 'app': 'app', // angular bundles '@angular/core': 'npm:@angular/core/bundles/core.umd.js', @@ -58,7 +59,12 @@ packages: { app: { main: './main.ts', - defaultExtension: 'ts' + defaultExtension: 'ts', + meta: { + './*.ts': { + loader: 'ng-loader' + } + } }, rxjs: { defaultExtension: 'js' diff --git a/public/docs/_examples/animations/ts/src/app/hero-list-auto.component.ts b/public/docs/_examples/animations/ts/src/app/hero-list-auto.component.ts index df7280d3ea..060417e309 100644 --- a/public/docs/_examples/animations/ts/src/app/hero-list-auto.component.ts +++ b/public/docs/_examples/animations/ts/src/app/hero-list-auto.component.ts @@ -11,7 +11,6 @@ import { import { Heroes } from './hero.service'; @Component({ - moduleId: module.id, selector: 'hero-list-auto', // #docregion template template: ` diff --git a/public/docs/_examples/animations/ts/src/app/hero-list-basic.component.ts b/public/docs/_examples/animations/ts/src/app/hero-list-basic.component.ts index a40f9ade94..d70a40a4ac 100644 --- a/public/docs/_examples/animations/ts/src/app/hero-list-basic.component.ts +++ b/public/docs/_examples/animations/ts/src/app/hero-list-basic.component.ts @@ -15,7 +15,6 @@ import { import { Heroes } from './hero.service'; @Component({ - moduleId: module.id, selector: 'hero-list-basic', // #enddocregion /* The click event calls hero.toggleState(), which diff --git a/public/docs/_examples/animations/ts/src/app/hero-list-combined-transitions.component.ts b/public/docs/_examples/animations/ts/src/app/hero-list-combined-transitions.component.ts index b40a0c3514..3847af40c4 100644 --- a/public/docs/_examples/animations/ts/src/app/hero-list-combined-transitions.component.ts +++ b/public/docs/_examples/animations/ts/src/app/hero-list-combined-transitions.component.ts @@ -14,7 +14,6 @@ import { import { Heroes } from './hero.service'; @Component({ - moduleId: module.id, selector: 'hero-list-combined-transitions', // #docregion template template: ` diff --git a/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave-states.component.ts b/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave-states.component.ts index a88e08f251..2a19b7615b 100644 --- a/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave-states.component.ts +++ b/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave-states.component.ts @@ -11,7 +11,6 @@ import { import { Heroes } from './hero.service'; @Component({ - moduleId: module.id, selector: 'hero-list-enter-leave-states', // #docregion template template: ` diff --git a/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave.component.ts b/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave.component.ts index 05944c84f1..0b38ee55e4 100644 --- a/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave.component.ts +++ b/public/docs/_examples/animations/ts/src/app/hero-list-enter-leave.component.ts @@ -11,7 +11,6 @@ import { import { Heroes } from './hero.service'; @Component({ - moduleId: module.id, selector: 'hero-list-enter-leave', // #docregion template template: ` diff --git a/public/docs/_examples/animations/ts/src/app/hero-list-groups.component.ts b/public/docs/_examples/animations/ts/src/app/hero-list-groups.component.ts index dda696eca2..a9583994fc 100644 --- a/public/docs/_examples/animations/ts/src/app/hero-list-groups.component.ts +++ b/public/docs/_examples/animations/ts/src/app/hero-list-groups.component.ts @@ -12,7 +12,6 @@ import { import { Heroes } from './hero.service'; @Component({ - moduleId: module.id, selector: 'hero-list-groups', template: `