I'm currently working on developing a basic Angular Application with Typescript and utilizing gulp for the building process. My goal is to store the html and css files separately for each component, following this structure:
components
- app.component.ts
- app.component.html
- app.component.scss
To include these files properly, I am referencing them in the TypeScript file like so:
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: require('./app.component.html')
})
export class AppComponent { }
However, there seems to be an issue as it attempts to load the file ./app.component.html.js based on the Chrome Network-Tools analysis.
By manually removing the .js extension from the requested url in my browser, the file displays correctly.
systemjs.config.js
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': '', // 'dist',
'@angular': 'libs/@angular',
'angular2-in-memory-web-api': 'libs/angular2-in-memory-web-api',
'rxjs': 'libs/rxjs'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
};
var ngPackageNames = [
'common',
'compiler',
'core',
'forms',
'http',
'platform-browser',
'platform-browser-dynamic',
'router',
'router-deprecated',
'upgrade'
];
// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
}
// Bundled (~40 requests):
function packUmd(pkgName) {
packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
}
// Most environments should use UMD; some (Karma) need the individual index files
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
// Add package entries for angular packages
ngPackageNames.forEach(setPackageConfig);
var config = {
map: map,
packages: packages
};
System.config(config);
})(this);
When storing the html and css within the components directly, everything functions as anticipated.