gpt4 book ai didi

c# - 使用 MVC 核心进行捆绑和缩小

转载 作者:行者123 更新时间:2023-12-01 23:15:06 27 4
gpt4 key购买 nike

我发现很多文章都向我指出 BundleConfig.cs 不再是 MVC 的东西。相反,我应该使用第三方工具来实现这一目标。至少,这是我的理解。我花了很多时间研究并试图理解,但在任何地方都找不到任何关于如何使用 bundlingconfig.json 实现此目的的明确说明。微软的一些文章,比如这篇https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.1&tabs=visual-studio%2Caspnetcore2x谈论默认模板如何使用它,但它没有告诉我他们到底是如何实现它的。另外,当我尝试使用 core 2.1 项目创建新模板时,它不存在。所以我很困惑如何让我的bundleconfig.json 工作。

现在,我热衷于从头开始并进行构建,因此我可以很好地了解它们的工作原理,以便在将来出现问题时可以修复它们。因此,我创建了一个全新的项目,其中没有任何内容,并添加了我的 Controller 、 View 以及获得基本网站所需的一切。然而,仅仅通过添加配置文件本身,它什么也不做。我希望它是 mvc 框架的一部分,并且它会拿起它并知道如何处理它。但我想情况并非如此,除了配置文件之外,我找不到任何关于需要添加什么内容才能使其工作的说明。

有人能给我指出正确的方向吗?

[
{
"outputFileName": "wwwroot/css/Test.css",
"inputFiles": [
"wwwroot/css/Global.css"
],
"minify": {
"enabled": true,
"renameLocals": true
}
}
]

然后在我的 cshtml 页面中添加

<link rel="stylesheet" href="~/css/Test.css" />

最佳答案

来自链接中的构建时执行捆绑和缩小部分:

The BuildBundlerMinifier NuGet package enables the execution of bundling and minification at build time. The package injects MSBuild Targets which run at build and clean time. The bundleconfig.json file is analyzed by the build process to produce the output files based on the defined configuration.

然后您需要做的就是将包添加到主项目

<PackageReference Include="BuildBundlerMinifier" Version="2.8.391" />

或者,如果您想从控制台捆绑和缩小,请添加以下 nuget:

<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.8.391" />

并在项目目录的控制台中dotnet bundle

关于c# - 使用 MVC 核心进行捆绑和缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52572404/

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