![]() ![]() min files will not even exist in your local checkout. The solution suggested in this post is based on not building the minified bundles locally. If you have the BuildBundlerMinifier package installed, go ahead and uninstall it. The first part doesn't require more explanation. In the following sections, I have a solution for each bullet. Minification and bundling should be done on the build server.The list of needed CSS and JavaScript files for each page should only be written once.Don't include the BuildBundlerMinifier package.This translates to a range of goals that I want to achieve with the solution presented in the rest of this post: You need to maintain a list of files in two places (`bundleconfig.json` and in HTML).You don't want that since that causes merge conflicts all the time. You need to compile the project to rebuild bundles (not a problem if using unbundled files locally, but still).On localhost, you never want to use bundled and minified files, why you can use tag helpers to reference the individual files locally and the bundles everywhere else: Ī pretty simple solution, but with a range of downsides: When building through either Visual Studio or dotnet build you now get the bundles generated and you can commit and push them. ![]() To have Visual Studio and dotnet build the bundles, you can install the BuildBundlerMinifier NuGet package: dotnet add package BuildBundlerMinifier I'll use only the CSS part in the rest of this post to simplify things, but everything applies to JavaScript files as well. In this example, we build a minified CSS bundle named and a minified JavaScript bundle named. ![]() For each bundle you want to create, there's a JSON object with an outputFileName and a set of files to include in the inputFiles array. "wwwroot/lib/bootstrap/dist/css/bootstrap.css", Here's an example of how the content could look like in the default template: [ To include bundling and minification, add a new file in the root of the web project named bundleconfig.json. In ASP.NET Core you typically add your static files in the Bundling and minification don't care where you place your files, but I tend to like this structure why the new elmah.io websites are based on it. The changes we made were from a baseline of the official docs, so let's dive in. I don't want to go into too much detail, since you can simply read through the documentation if you want. Let's start by looking at how the documentation suggests implementing bundling and minification in ASP.NET Core. In this post, I'll go through the possibilities we went through when migrating and what we ended up choosing. We used the namespace in ASP.NET MVC, combined with the AspNetBundling and BundleTransformer packages for some additional features like generating source maps. When migrating our websites to ASP.NET Core, we had to find a new way to bundle and minify JavaScript and CSS files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |