The ASP.NET Core RTM release introduced BundlerMinifier.Core
, a new Bundling and Minification tool that can be easily integrated into existing ASP.NET Core applications and doesn't require any external extensions or script files.
To use this tool, simply add a reference to BundlerMinifier.Core
within the tools
section of your existing project.json
file as seen below :
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
After adding the tool, you'll need to add a bundleconfig.json
file in your project that will be used to configure the files that you wish to include within your bundles. A minimal configuration can be seen below :
[
{
"outputFileName": "wwwroot/css/site.min.css",
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
"minify": {
"enabled": true,
"renameLocals": true
},
"sourceMap": false
},
{
"outputFileName": "wwwroot/js/semantic.validation.min.js",
"inputFiles": [
"wwwroot/js/semantic.validation.js"
],
"minify": {
"enabled": true,
"renameLocals": true
}
}
]
After your bundles have been configured, you can bundle and minify your existing files via the following command :
dotnet bundle
The Bundling and Minification process can be automated as part of the build process by adding the dotnet bundle
command in the precompile section of your existing project.json
file :
"scripts": {
"precompile": [
"dotnet bundle"
]
}
You can see a list of all of the available commands and their descriptions below :
bundleconfig.json
file to bundle and minify your specified files.dotnet bundle
whenever an existing input file from the bundleconfig.json
configuration to bundle your files.