How to manage ASP.NET Core bundleconfig.json for multiple environments?

孤人 提交于 2019-11-30 21:12:15

I think I found my answer. I was about to create an HTML helper to read the bundleconfig.json for the development environment, but it appears I'm not the first one to think this was a good idea. Note that the .NET Core implementation is linked to at the bottom of the page

https://github.com/madskristensen/BundlerMinifier/wiki/Unbundling-scripts-for-debugging

Edit

For the .NET Core implementation, the reference to the bundleconfig.json was expecting it to be in a /Configs folder, which may or may not be the case in your project. For me, I just had it in the root of the project.

Edit

So this doesn't work if the source files are outside of the wwwroot folder. Having files outside of the wwwroot folder is completely reasonable, so I'm investigating having the html helper point to a path that will stream the files in debug mode

Possible Solution

Here's my evolution of the solution:

https://gist.github.com/rupe120/512a9eb837383963f80fd9ef4984eb15

Update

I modified my solution to use {*filePath} in the route definition, so there's now no need to encode the path

Update

I think this is the last major update I'll do. I replaced the static base route string with the outputFileName values from the bundleconfig.json. So now there's as many debug routes as there will be minified files and no fear what so ever of name collisions. Additionally you can see what files are included in which bundle when you're debugging, which I think is pretty cool.

Im with Josh on this one, seems like madness having to maintain two lists. Has anybody come back with a better build in solution without using a MvcHtmlString helper!

"sourceMap": true

This enables debugging into your js in if enabled in the bundleconfig.json but I have noticed if you are going bundling it does not generate the maps correctly, references the combined and the each mapped file...

Smidge seems to provide this functionality - with a simple flag - debug="true"

<environment names="Development">
    <script src="my-awesome-js-bundle" type="text/javascript" debug="true"></script>
</environment>
<environment names="Staging,Production">
    <script src="my-awesome-js-bundle" type="text/javascript"></script>
</environment>

Webpack or gulp is the way to go - which one, that`s debatable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!