0

I'm using Angular Elements in C# MVC project.

When I include angular elements build file directly in main.cshtml like <script type="text/javascript" src="~/Script/Angular/artifi-graphics.js"></script> it's working perfectly.

BUT

when I try to add build file in the bundle

bundles.Add(new ScriptBundle("~/bundles/Layout_8_CommonModule")
                .Include("~/Script/Angular/artifigraphics.js")

then the project is not loading.

In console network status of the request is pending and after some time it gets failed. enter image description here

piet.t
  • 11,718
  • 21
  • 43
  • 52
Sunil Kashyap
  • 2,946
  • 2
  • 15
  • 31
  • Possible duplicate of [ASP.NET MVC Bundle not rendering script files on staging server. It works on development server](https://stackoverflow.com/questions/21270834/asp-net-mvc-bundle-not-rendering-script-files-on-staging-server-it-works-on-dev) – Rahul Sharma May 29 '19 at 10:17
  • @RahulSharma already tried this solution but not working – Sunil Kashyap May 29 '19 at 10:25
  • Okay, have you tried this link: https://mariusschulz.com/blog/bundling-and-minifying-an-angularjs-application-with-asp-net-mvc – Rahul Sharma May 29 '19 at 10:28
  • yes tried this also but no luck – Sunil Kashyap May 29 '19 at 10:32
  • Unlike .NET references, Javascript files need to load based on the order. Angular App should be loaded first, then the related components. You would have to include it in the app file using `Include` method instead of `IncludeDirectory` method. – Rahul Sharma May 29 '19 at 10:41
  • I tried with `Include` and `IncludeDirectory` but still not working, created saperate bundle though but still not working. – Sunil Kashyap May 29 '19 at 11:24
  • Not quite sure but usually this happens when some extension is blocking your request that is why it is in `pending` status. Try disabling some Chrome extensions like `Adblocker` and then try again. – Rahul Sharma May 29 '19 at 11:33
  • actually, when I debug CS code the pointer is getting stuck on bundling, and also tried in incognito mode and disabling adblocker extension as you suggested but still no luck – Sunil Kashyap May 29 '19 at 11:41
  • Okay, are you including a `_Layout` from your Shared folder for your View or is your page without a common layout? And what do you mean by "debug CS code the pointer is getting stuck on bundling"? Is it throwing some error? – Rahul Sharma May 29 '19 at 11:44
  • Did you get this resolved ? – Rahul Sharma Jun 06 '19 at 13:19
  • no @RahulSharma, I googled a lot and find out minified js unable to bundle with regular js in c# bundling – Sunil Kashyap Jun 06 '19 at 16:36
  • so basically I just add script tag in `main.cshtml` file just like including the normal script in HTML file – Sunil Kashyap Jun 06 '19 at 16:37

1 Answers1

1

after searching a lot find out C# bundling is not so intelligent to bundle angular production build files which are also merged by node concat library.

so I just added angular bundle into main.cshtml file just like we add scripts.

Sunil Kashyap
  • 2,946
  • 2
  • 15
  • 31