DEV Community

Cover image for Managing ASP.NET Core MVC front-end dependencies with npm and webpack (part 1)

Managing ASP.NET Core MVC front-end dependencies with npm and webpack (part 1)

Lars Willemsens on April 09, 2021

.NET 8 provides a couple of great project templates to get you up and running quickly. However, the MPA (multiple-page application) is not getting ...
Collapse
 
bkdevhub profile image
BK • • Edited

In case your application cannot find/load the site.entry.js File please check program.cs if the following line of code is included:
app.UseStaticFiles();
Took me a couple of hours to find this.

Collapse
 
_clarkson profile image
Matt Clarkson •

Kudos, nice write up 🙌🏼

Collapse
 
benhumphrys profile image
Ben Humphrys •

Great article - thanks so much!

Collapse
 
paulo673 profile image
Paulo Barbosa •

This is great content about asp.net with webpack. Thanks for taking the time to contribute to the growth of many devs

Collapse
 
wokle profile image
AslamHamdi •

Im trying to import vue in entry.js. Then, when I try to use vue in other page, it shows Vue is not defined. But when I use cdn link and put it in layout.cshtml, it worked.

Collapse
 
larswillemsens profile image
Lars Willemsens •

Which bundles and pages do you have? If Vue is only imported for a single bundle then it won't be available on other pages that don't use this bundle.

Collapse
 
wokle profile image
AslamHamdi •

Sorry. I'm new to node js. But here is what I did:

  1. I create an asp.net core MVC apps
  2. Then, I did exactly like the instruction in the post.
  3. I download vue and lodash using npm
  4. Then I import vue and lodash in entry.js and run 'npm run build'
  5. I create a page that share the same layout, _Layout.cshtml which share the same script site.entry.js

As for lodash, it worked fine. But for Vue, when I create a vue app in the other page it said Vue is not defined. But if I create a vue app in layout page and write the js code in site.js it worked.

Thread Thread
 
larswillemsens profile image
Lars Willemsens •

So you have site.entry.js, which is loaded from two different pages, but only on one page it throws an error?

Thread Thread
 
wokle profile image
AslamHamdi •

Yes. I loaded site.entry.js in _Layout.cshtml. I create new page which render in _Layout.cshtml . This new page throws an error.

Collapse
 
jakobmatias profile image
Jakob M. Melbye •

Thank you very much - this was very helpful! :)

Collapse
 
beginner profile image
Mo •

Thank you!

Collapse
 
beginner profile image
Mo •

Dank u :)

Collapse
 
gary_momenee_976ca5626525 profile image
gary momenee •

It took me a while to find this, glad I did. Thanks a lot.