I've created an Angular2 application integrated with ASP.NET and served by IIS. This application is to be used by multiple clients and they would like the ability to customize the look and feel of the application to fit their branding. I'm using some aspects of ASP.NET MVC5's framework to make this possible.
The application is working as expected for most things, but I have two big stumbling blocks utilizing the cli that I can't seem to figure out.
Here is the basic folder structure of the application(there are other files and directories, but I'm excluding them as I don't believe they are relevant to the question):
Solution.sln
Web
Controllers
dist
Models
src
Views
Shared
_Layout.cshtml
.angular-cli.json
package.json
Web.config
Global.asax
The only relevant update that I've made to my .angular-cli.json file is that I changed the { apps: { index: '' } } value to be "../Views/Shared/_Layout.cshtml" instead of the default "index.html".
When I run ng build from within the Web directory, the application compiles and the correct script tags are placed in the _Layout.cshtml file right before the closing body tag as expected.
I'm not sure if these problems stem from the same root cause. I assume they do which is why I've put both here, but if they seem to be separate questions, I can break them apart.
Issue 1
If I run ng build multiple times, it doesn't remove and replace the script tags it creates in the _Layout.cshtml file as expected, but instead continues to append new script tags before the closing body tag. So if I run ng build twice in development mode, I'll get the same set of script tags in the file twice.
Any ideas as to what I would need to change to get the expected functionality back from ng build?
Issue 2
Now when I run ng build --watch, the build seems to end up in an endless loop. It continues packaging the assets over and over.
Any ideas as to what might be causing the infinite loop and how I can get ng build --watch to work properly with this setup?
I didn't have either of these issues with the index.html file, but unfortunately, I need to use the _Layout.cshtml file as my index file. I can create a custom prebuild npm task to clean up the script tags, but it doesn't seem like I should have to. I have not figured out a work around for the watch task issue.
UPDATE
As I suspected, this has nothing to do with the fact that it is an *.cshtml file, but rather due to the fact that the apps/index location is outside of the src folder.
Steps to reproduce:
npm install @angular/clinode_modules/.bin/ng new test-custom-index- Move
test-custom-index/src/index.htmltotest-custom-index/index.html - Update the
.angular-cli.jsonso index property is"index": "../index.html"instead of "index": "index.html" - From the
test-custom-indexdirectory runnode_modules/.bin/ng buildtwo times consecutively and you will see the duplicate script entries in theindex.htmlfile. OR runnode_modules/.bin/ng build --watchand watch it get caught in an infinite loop.
Any help would be greatly appreciated!!!