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
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 bustingIs there a chatroom for webpack besides gitter? that appears to be dead.
I don't think so
People generally tend to move away from Webpack, not to Webpack anyway
Oh, really?
I'm moving to it because I was under the impression that was the thing to do from Microsoft
Webpack is not a Microsoft product, if I'm not mistaken
No, but they recommended it as an alternative