How to use Bundle&Minifier and bundleconfig.json in ASP.NET Core
2017-01-04 15:03
1116 查看
2017 年9月27日更新
在.csproj 文件中的配置
引言
我们在ASP.NET MVC 中经常会用到 bundleConfig.cs 文件来进行我们 css 和 js 的绑定, 那么在ASP.NET Core 中我们应该如何使用呢?
步骤一
在 Visual Studio 2015 工具->扩展和更新 中下载插件
然后重启 Visual Studio 2015
步骤二
在你的ASP.NET Core 项目的 Web 层中 的 project.json 文件中添加如下配置:
在上面的
则会在编译时就自动再重新生成一遍,如果不想这样的话,可以去除。
步骤三
在 程序包管理器控制台 上输入 dotnet bundle 程序就会自动找到 bundleconfig.json文件 进行编译。
差不多就是这样的啦。
步骤四
如何配置 bundleconfig.json 文件 :
参考文献
http://dotnetthoughts.net/bundling-and-minification-in-aspnet-core/
https://github.com/madskristensen/BundlerMinifier/wiki
在.csproj 文件中的配置
<Project Sdk="Microsoft.NET.Sdk.Web"> //... <ItemGroup> <PackageReference Include="BundlerMinifier.Core" Version="2.4.401" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.4.337" /> </ItemGroup> <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> <Exec Command="dotnet bundle" /> </Target> //... </Project>
引言
我们在ASP.NET MVC 中经常会用到 bundleConfig.cs 文件来进行我们 css 和 js 的绑定, 那么在ASP.NET Core 中我们应该如何使用呢?
步骤一
在 Visual Studio 2015 工具->扩展和更新 中下载插件
然后重启 Visual Studio 2015
步骤二
在你的ASP.NET Core 项目的 Web 层中 的 project.json 文件中添加如下配置:
"tools": { "BundlerMinifier.Core": "2.0.238" }, "scripts": { "precompile": [ "dotnet bundle" ] }
在上面的
"scripts":{ "precompile":["dotnet bundle"] }
则会在编译时就自动再重新生成一遍,如果不想这样的话,可以去除。
步骤三
在 程序包管理器控制台 上输入 dotnet bundle 程序就会自动找到 bundleconfig.json文件 进行编译。
差不多就是这样的啦。
步骤四
如何配置 bundleconfig.json 文件 :
[ { "outputFileName": "output/bundle.css", "inputFiles": [ "css/lib/**/*.css", // globbing patterns are supported "css/input/site.css" ], "minify": { "enabled": true, "commentMode": "all" } }, { "outputFileName": "output/all.js", "inputFiles": [ "js/*.js", "!js/ignore.js" // start with a ! to exclude files ] }, { "outputFileName": "output/app.js", "inputFiles": [ "input/main.js", "input/core/*.js" // all .js files in input/core/ ] } ]
参考文献
http://dotnetthoughts.net/bundling-and-minification-in-aspnet-core/
https://github.com/madskristensen/BundlerMinifier/wiki
相关文章推荐
- metasploit学习笔记之服务扫描和查点
- 如何在ASP.NET MVC 中获取当前URL、controller、action
- 漫步ASP.NET MVC的处理管线
- metasploit学习笔记之主机探测和端口扫描
- Asp.Net_Mvc_@Html.xxx()的扩展
- [转]How do you create a custom AuthorizeAttribute in ASP.NET Core?
- Asp.Net_Mvc_获取当前Url、Controller、Action
- [转]ASP.NET Core 中间件详解及项目实战
- [转]如何在ASP.NET Core中实现一个基础的身份认证
- [转]ASP.NET Core 之 Identity 入门(三)
- [转]ASP.NET Core 之 Identity 入门(二)
- [转]ASP.NET Core 之 Identity 入门(一)
- ASP.NET Core应用的错误处理[2]:DeveloperExceptionPageMiddleware中间件如何呈现“开发者异常页面”
- AJAX ASP/PHP 实例
- 异步编程: Asp.net中使用Async/Await
- ASP.NET WebForm
- ASP .NET DropDownList多级联动事件
- 创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表
- Sha256加密
- Spring cache 配置代理 改为aspectj