css - 当 EnableOptimizations=false 时将 .less 输出为 .css

标签 css asp.net-mvc less bundling-and-minification dotless

我有以下 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/

相关文章:

javascript - 如何管理从多个按钮打开 "same jquery ui dialog"

css - Google Chrome 在简单的 CSS 页面上没有响应 - 如何修复?

css - lesscss如何转义括号

css - 我是否将供应商前缀的 LESS 过于复杂化了?

asp.net-mvc - 自定义成员(member)提供者或角色我自己的实现

css - 从 SCSS 到 LESS 的字体堆栈?

jQuery Highlight 假定背景为白色

html - 跨选择器的 CSS3 多重背景

asp.net-mvc - 下载生成的文件后重定向/显示 View

asp.net - 我需要 inetpub/wwwroot 中的哪个程序集/DLL 来启动 aspx 页面?