gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 02:24:00 25 4
gpt4 key购买 nike

我正在表演 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com