I have an Asp mvc 5 site with angular9.
My angular 9 is built into /Scripts/angularDist directory.
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"App": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "Scripts/angularDist/",
"index": "src/index.html",
"main": "src/main.ts",
I am returning angular index.html file (src/index.html) in my default mvc controller action (Home/Index):
public ActionResult Index()
{
var htmlPath = Server.MapPath("~/Scripts/angularDist/index.html");
return new FilePathResult(htmlPath, "text/html");
}
The ngsw-config.json is configured to use the index.html:
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.json",
"/*.css",
"/*.js"
],
And finally i register the service worker via the ServiceWorker module in app.module:
ServiceWorkerModule.register('/Scripts/angularDist/ngsw-worker.js',
{ scope: '/Scripts/angularDist/', registrationStrategy: 'registerImmediately' }),
So since angular and the pwa are in a subdirectory, the only way i managed to get the relative paths to be registered in the service worker is by using:
ng build --prod --base-href=/Scripts/angularDist/
So the urls in the ngsw.json look like this now:
"urls": [
"/Scripts/angularDist/1-es2015.a1dd7840a1fc1224a25c.js",
"/Scripts/angularDist/1-es5.a1dd7840a1fc1224a25c.js",
So applicaiton works fines and the service worker is registered.However the problem is that my url is now:
http://localhost:5114/Scripts/angularDist/login
So my question is, how can i set the relative path for the generated .js and .css files in the services worker to be prefixed with my sub directory (/Scripts/angularDist) without changing my url.
Is there another way of settings this up?
The problem that i have:
- I do not want/need to display the /Scripts/angularDist path in the url
- All http calls now fail to the web api because the relative path is appended to the api calls
Edit
I tried using ng build --prod --base-href=./ which then loads the url without the /Scripts/angularDist and the relative paths in the service worker work correctly but then it looks like the scope of the service worker does not cover the root url and app does not work offline