使用WebOptimizer和预最小化文件?



如果我使用WebOptimizer——https://github.com/ligershark/WebOptimizer——在我的ASP中进行捆绑和缩小。Net Core应用程序是否需要保留正在使用的客户端库的缩小版本?

例如,在布局页面中是否还需要这样的代码:

<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
</environment>

或者我可以有链接到未缩小的版本和WebOptimizer将缩小它的飞行,然后我可以从我的项目中删除boostrap.min.css文件?

在一个相关的注意事项上,如果WebOptimizer中间件遇到一个预先最小化的文件,它会怎么做?

这是一个有点老的问题,但我认为这是很好的回答。

你可以在你的配置中配置bundle来缩小或不缩小这个文件,而不是在HTML中这样做,并且在你的HTML中正常引用bootstrap.css。

您可以在这里找到如何完成的示例:https://www.vinayjadav.com/posts/bundle-js-css-aspnet-core

public static class WebOptimizerBootstrapper
{
public static void Configure(ServiceRegistry services)
{
string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
bool isDevelopment = environment == Environments.Development;
services.AddWebOptimizer(pipeline =>
{
pipeline.AddCssBundle("/css/site.css", "css/**/*css");
pipeline.AddJavaScriptBundle("/js/site.js", "js/**/*.js");
if (!isDevelopment)
{
pipeline.MinifyCssFiles();
pipeline.MinifyJsFiles();
}
});
}
}

在Program.cs (for .net core)

builder.Services.AddWebOptimizer(services=>WebOptimizerBootstraper.Configure)

最新更新