asp.net core 的文档显示了如何操作捆绑和缩小 https://docs.asp.net/en/latest/client-side/bundling-and-minification.html css
and js
使用 grunt 或 gulp 的文件。
但是,当我使用 vs 2015 创建项目时,它添加了bundleconfig.json
文件到项目中。我想缩小 wwwroot/js 文件夹中的所有 js 文件。所以我更新了bundleconfig.json中的现有行以使用通配符*
{
"outputFileName": "wwwroot/js/*.min.js",
"inputFiles": [
"wwwroot/js/*.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optinally generate .map file
"sourceMap": false
}
但是当我发布项目时出现错误
处理 wwwroot/js/*.min.js 路径中的非法字符。范围
名称:路径
截至 2021 年 3 月 - the Microsoft 推荐的方法 https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-5.0#choose-a-bundling-and-minification-strategy是利用 Mads Kristensen(Visual Studio 团队的 PM)创建的 WebOptimizer Core nuget 包 -https://www.nuget.org/packages/LigerShark.WebOptimizer.Core/ https://www.nuget.org/packages/LigerShark.WebOptimizer.Core/
它不使用bundleConfig.json
文件,并支持通过 Startup.ConfigureServices() 进行配置,但您当然可以编写一个小静态助手,它返回一个操作并通过 JSON.NET 或 System.Text.Json 解析出您的 bundleConfig.json 文件,如果您有的话大量的捆绑包,并且已经花时间以正确的方式获取 json 文件。然后在启动中,您可以提供辅助操作来调用services.AddWebOptimizer(action)
.
WebOptimizer 具有标签助手,可帮助添加<link>
and <script>
CSHTML 文件中的标签。
您可以从 GitHub 存储库中查看 README 的详细信息:https://github.com/ligershark/WebOptimizer https://github.com/ligershark/WebOptimizer
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)