C
C#16h ago
Turn2Jesus2

How do I get webpack to integrate with cshtml files?

I have an ASP.NET Framework 4.8 MVC project that has cshtml files. I currently do bundling via BundleConfig.js. I need to migrate to something else because we are migrating to ASP.NET [Core] and that functionality doesn't exist there. Microsoft recommends switching to something like WebPack. I am switching to webpack now before migrating to .NET so that the amount of churn necessary for the .NET upgrade is minimized. However, I'm finding it hard to see examples of how this integrates with .cshtml files. Currently, my bundles are generated with a hash to break the cache when we deploy. I am expecting something similar with webpack. However, my generated bundles don't have hashes (and they probably don't need them). But how do I get my cshtml files to reference a hashed version of the assets so that when I deploy updates to the website, users download the new bundles? My current option is to just have webpack generate the assets and statically link to those assets from within the cshtml file, but when I push updates, clients will download the old versions which would be incompatible with the new version. I'm not sure why I'm having so much trouble. I figured that if Microsoft recommends it that there'd be examples of how to migrate to it. Thank you for any help!
6 Replies
Angius
Angius14h ago
Generally speaking, you would not make the hash part of the file name, but rather use asp-append-version="true" That appends a ?v=[hash] query string to the file path, which is enough for cache busting
Turn2Jesus2
Turn2Jesus2OP13h ago
Is there a chatroom for webpack besides gitter? that appears to be dead.
Angius
Angius13h ago
I don't think so People generally tend to move away from Webpack, not to Webpack anyway
Turn2Jesus2
Turn2Jesus2OP13h ago
Oh, really? I'm moving to it because I was under the impression that was the thing to do from Microsoft
Angius
Angius13h ago
Webpack is not a Microsoft product, if I'm not mistaken
Turn2Jesus2
Turn2Jesus2OP13h ago
No, but they recommended it as an alternative

Did you find this page helpful?