我有以下 ASP.NET MVC 包:
var lessBundle = new Bundle("~/bundles/common.css");
lessBundle.Include("~/CSS/Header.less",
"~/CSS/Footer.less");
lessBundle.Transforms.Add(new LessTransform());
bundles.Add(lessBundle);
当 BundleTable.EnableOptimizations = true
时,这会按预期捆绑在一起,并输出为:
<link href="/bundles/common.css?v=xxxx-xxxx-xxxx-xxxx" rel="stylesheet"/>
当 BundleTable.EnableOptimizations = false
时,输出为:
<link href="/CSS/Header.less" rel="stylesheet"/>
<link href="/CSS/Footer.less" rel="stylesheet"/>
有没有办法改变它,使文件扩展名显示为 .css
而不是 .less
?
因此:
<link href="/CSS/Header.css" rel="stylesheet"/>
<link href="/CSS/Footer.css" rel="stylesheet"/>
最佳答案
当 EnableOptimizations
设置为 false
时,我认为您无法更改文件扩展名,如 documentation 所述...
Unless EnableOptimizations is true or the debug attribute in the compilation Element in the Web.config file is set to false, files will not be bundled or minified. Additionally, the .min version of files will not be used, the full debug versions will be selected. EnableOptimizations overrides the debug attribute in the compilation Element in the Web.config file
这意味着编译模式和 EnableOptimizations
属性将定义这些资源是否会被捆绑和缩小。在您的情况下,当您将 EnableOptimizations
设置为 false
时,优化引擎将不会对这些资源进行任何转换并完全按照您在此处定义的方式呈现它们...
lessBundle.Include("~/CSS/Header.less",
"~/CSS/Footer.less");
因此输出 html(在 razor 的帮助下)将呈现以下链接...
<link href="/CSS/Header.less" rel="stylesheet"/>
<link href="/CSS/Footer.less" rel="stylesheet"/>
这是默认行为,如果你不想做任何花哨的事情,没有什么能阻止你偷看 asp.net stack ...谢天谢地,它是开源的,可以实现您想要的行为
更新
实际上,优化框架的源代码是一个单独的扩展,您可以找到 here
关于css - 当 EnableOptimizations=false 时将 .less 输出为 .css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25601046/