My Visual Studio MVC project contains a systemjs.config.js file in the Scripts folder at root/Scripts/systemjs.config.js.
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'libs/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: '/Scripts/app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'.': {
defaultJSExtensions: 'js'
}
}
});
})(this);
All Angular JavaScript files are located in Scripts/app, while modules are in libs.
In development, my website URL is www.mywebsite.com/firstpage, but in production it is www.mywebsite.com/user/firstpage.
The Angular app is loaded in the master layout of the page using:
<!-- Load libraries -->
<script src="~/libs/core-js/client/shim.min.js"></script>
<script src="~/libs/zone.js/dist/zone.js"></script>
<script src="~/libs/systemjs/dist/system.src.js"></script>
<!-- Configure SystemJS -->
<script src="~/Scripts/systemjs.config.js"></script>
<script>
System.import('@Url.Content("~/Scripts/app/main")').catch(function (err)
{
console.error(err);
});
</script>
Angular loads fine on the home page locally, but I get a "main.js not found" error on the production home page.
www.mywebsite.com/user/Scripts/app/main 404 (Not Found)
Adjusting URLs allows me to load the main.js file, but the libs files still give 404 errors because they are looking from mywebsite.com instead of mywebsite.com/user in production.
How can I make the paths work consistently from the root of the website in both production and local environments?