javascript - 如何阻止 ASP.NET Core 2.0 MVC 缩小修改特定文件?

标签 javascript visual-studio asp.net-core asp.net-core-2.0 bundling-and-minification

我正在表演 Bundling and Minification in ASP.NET Core 2.0 MVC而且我遇到了一个问题,即在不应该进行缩小的情况下进行缩小。在我的页面中,我有以下脚本标记:

<script src="https://code.jquery.com/jquery-3.3.1.min.js"
        integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT"
        crossorigin="anonymous"
        asp-fallback-test="window.jQuery"
        asp-fallback-src="~/js/jquery.min.js">
</script>

在我的 bundleconfig.json 中有以下部分:

{
    "outputFileName": "wwwroot/js/jquery.min.js",
    "inputFiles": [
        "node_modules/jquery/dist/jquery.min.js"
    ],
    "minify": {
        "enabled": false
    }
}

问题是 ~/js/jquery.min.js 文件在通过此捆绑/缩小过程进行转换时丢失了尾随的换行符,这使得文件的预期哈希值不再比赛。作为一种解决方法,我可以为完整性值指定 2 个哈希值以支持带有或不带有换行符的文件,如下所示:

integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT sha384-I7/UTpkJas2maMjJpGmrvEgQecqO8Dta/9Wwh+cQrH6Jj984WRRFhWg4MV/oTkIW"

但这比确保缩小不触及该文件效率低。我怎样才能阻止这个换行符被 trim ?

最佳答案

尝试以下配置:

//1. by default outputMode is singleLine which removes new lines and output on a single line. We are setting it to none.
{
    "outputFileName": "wwwroot/js/jquery.min.js",
    "inputFiles": [
        "node_modules/jquery/dist/jquery.min.js"
     ],
     "minify": {
           "enabled": false,
            outputMode: "none"         
      }
}


//Alternatively, outputMode = "multipleLines" should work with a indentSize of 0 as well.
//In this mode , output file has each line indented by specified indentSize
{
    "outputFileName": "wwwroot/js/jquery.min.js",
    "inputFiles": [
        "node_modules/jquery/dist/jquery.min.js"
     ],
      "minify": {
       "enabled": false,
        outputMode: "multipleLines",
         indentSize: 0
    }
}

您可以阅读有关 javascript minifier 的可用设置的信息 here

关于javascript - 如何阻止 ASP.NET Core 2.0 MVC 缩小修改特定文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50196251/

相关文章:

javascript - 如何在点击时从购物车中删除商品?

javascript - 如何启动和停止使用 youtube iframe API 创建的 YouTube 视频?

c# - 从 Visual Studio 扩展访问当前的 Microsoft 帐户

c# - 呈现 ViewComponent 返回 HTML 500 错误

javascript - Angular 2 中页面加载时的动画元素

javascript - 外部 javascript 在模拟器中工作但在 ios 设备中不起作用

visual-studio - 如何合并整个 TFS 分支

c# - MSVS 解决方案文件生成器?

c# - 在 C# 中将 IHtmlContent/TagBuilder 转换为字符串

asp.net-core - .NET Core 替代 ThreadPool.QueueUserWorkItem