【发布时间】:2014-01-21 21:10:50
【问题描述】:
我正在尝试使用无点来完成以下结构:
styles/variables.less - 包含所有变量,如下所示
@color:green;
styles/component1.less - 导入 variables.less 的一些随机组件特定样式
@import "variables";
body {
background:@color;
}
styles/component2.less - 更多样式也导入全局 variables.less 文件
@import "variables";
a {
color:@color;
}
BundleConfig.cs - 如下声明捆绑包。我正在使用这个捆绑添加:https://gist.github.com/benfoster/3924025
bundles.Add(new Bundle("~/styles/css", new LessTransform()).Include("~/styles/component1.less", "~/styles/component2.less"));
当 Debug 设置为 true
但是当 Debug 设置为 false
只有在 bundle 的 Include 方法中传入的第一个文件才能解析 @import "variables"。其余的都失败了。
下面是先声明“~/styles/component1.less”的输出
bundles.Add(new Bundle("~/styles/css", new LessTransform()).Include("~/styles/component1.less", "~/styles/component2.less"));
首先声明“~/styles/component2.less”时的输出
bundles.Add(new Bundle("~/styles/css", new LessTransform()).Include("~/styles/component2.less", "~/styles/component1.less"));
奇怪的是,如果我在组件 1 和组件 2 中导入不同的文件,它会起作用
例如,如果我在任一文件中将“varibales”重命名为“variables.less”,只是为了使这些导入看起来有点不同。有用。如下所示
styles/component1.less
@import "variables.less"; // added extension here
body {
background:@color;
}
有什么想法吗?这几天我一直在摆弄这个..
编辑
使用这种结构的原因:
在调试模式下单独发送更少的文件,因为这样更容易调试。行号 cmets 不是很helpful
在生产环境中连接和缩小所有 less 文件。
在每个文件的顶部添加@import“变量”是丑陋的。
因此,尝试将 variables.less 声明为 .Include("variables.less", file-dependant-on-variables.less, ...) 的一部分 由于此处提到的一些范围问题,这显然不起作用:Dotless - Can't reference less variable in separate file with MVC Bundling
有一个解决方法,连接每个 less 文件的内容,并使用 Less 来解析连接的文件。这里的例子,https://groups.google.com/forum/?fromgroups#!topic/dotless/j-8OP1dNjUY
但在那种情况下,我似乎无法获得已解析文件的缩小版本。
【问题讨论】:
标签: css asp.net-mvc less bundling-and-minification dotless