如何使用Bundler& Visual Studio 2015中的Minifier工具 [英] How to use Bundler & Minifier tool in Visual Studio 2015
问题描述
最近,我使用ASP.NET Core开发我的项目.我有一个类似的问题:我的查看"页面中有很多要引用的css
和js
文件,因此,如果存在该工具,可以将一些css或js合并为一个.就像跟随
Recently, I use ASP.NET Core to develop my project. I have a question like that: there is many css
and js
file I want refer in my View page, so If it is exist a tool that can combine some css or js to one. It is like following
<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文件?
Then I search it on Google, I got the tool Bundler& Minifier
, an extension in Visual Studio. I want to know how to write the bundleconfig.json file in my project? and how to use it to combine the css or js file?
推荐答案
您可以使用多种方式使用Bundler& asp.net核心项目中的Minifier.最常见的是使用 BundlerMinifier.Core 工具
There are number of ways you can use Bundler & Minifier in asp.net core project. Most common is using BundlerMinifier.Core tool
要使用BundlerMinifier.Core工具,只需在现有project.json文件的tools部分中添加对BundlerMinifier.Core的引用,如下所示:
To use BundlerMinifier.Core 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"
}
添加工具后,您需要在项目中添加bundleconfig.json文件,该文件将用于配置希望包含在捆绑软件中的文件.最低配置如下所示:
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
还有一个 Bundler&可用于Visual Studio的Minifier扩展程序,它将帮助您捆绑和缩小文件.
There is also a Bundler & Minifier extension available for Visual Studio which will help you to bundle and minify your files.
这篇关于如何使用Bundler& Visual Studio 2015中的Minifier工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!