最近,我使用ASP.NET Core来开发我的项目。我有一个这样的问题:有很多css
和js
文件我想在我查看网页参考,所以如果它是存在的工具,可一些CSS或JS合并为一个。就像下面
<link href="~/Content/css/a1.css" rel="stylesheet" asp-append-version="true" />
<link href="~/Content/css/a2.css" rel="stylesheet" asp-append-version="true" />
我想得出的结果是:
<link href="~/bundles/css/a.min.css" rel="stylesheet" asp-append-version="true" />
然后,我在Google上进行搜索,得到了该工具Bundler& Minifier
(Visual Studio中的扩展程序)。我想知道如何在项目中编写bundleconfig.json文件吗?以及如何使用它来结合css或js文件?
在asp.net核心项目中可以使用多种方法使用Bundler&Minifier。最常见的是使用BundlerMinifier.Core工具
要使用BundlerMinifier.Core工具,只需在现有project.json文件的tools部分中添加对BundlerMinifier.Core的引用,如下所示:
"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"
}
添加该工具后,您需要在项目中添加一个bundleconfig.json文件,该文件将用于配置希望包含在捆绑软件中的文件。最低配置如下所示:
[
{
"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
}
}
]
配置捆绑包后,您可以通过以下命令捆绑并缩小现有文件:
dotnet bundle
Visual Studio还提供了Bundler&Minifier扩展程序,它将帮助您捆绑和缩小文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句