我试图使用无点来完成以下结构:
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"));
奇怪的是 - 如果我在 component1 和 component2 中导入不同的文件,它会起作用
例如,如果我在任一文件中将“varibales”重命名为“variables.less”,只是为了让这些导入看起来有点不同。有用。像下面
样式/component1.less
@import "variables.less"; // added extension here
body {
background:@color;
}
有什么想法吗?这几天我一直在摆弄这个..
编辑
使用这种结构的原因:
在调试模式下发送单独的更少文件,因为它更容易调试。行号注释不是很有帮助
在生产环境中连接和缩小所有较少的文件。
在每个文件的顶部添加 @import "variables" 是丑陋的。
因此,尝试将 variables.less 声明为 .Include("variables.less", file-dependant-on-variables.less, ...) 的一部分,由于此处提到的一些范围问题,这显然不起作用:Dotless - Can't使用 MVC 捆绑在单独的文件中引用较少的变量
有一个解决方法,连接每个 less 文件的内容,并使用 Less 来解析连接的文件。这里的例子,https://groups.google.com/forum/?fromgroups#!topic/dotless/j-8OP1dNjUY
但在那种情况下,我似乎无法获得解析文件的缩小版本。