Trying to achieve a specific structure using dotless:
styles/variables.less - contains all variables like this
@color:green;
styles/component1.less - random component specific style importing variables.less
@import "variables";
body {
background:@color;
}
styles/component2.less - more styles importing global variables.less file
@import "variables";
a {
color:@color;
}
BundleConfig.cs - bundle declaration as follows using a bundling addition: https://gist.github.com/benfoster/3924025
bundles.Add(new Bundle("~/styles/css", new LessTransform()).Include("~/styles/component1.less", "~/styles/component2.less"));
Works fine when Debug is true
However, when Debug is false
Only the first file included in the bundle's Include method recognizes @import "variables". The rest fail.
Output when declaring "~/styles/component1.less" first
bundles.Add(new Bundle("~/styles/css", new LessTransform()).Include("~/styles/component1.less", "~/styles/component2.less"));
Output when declaring "~/styles/component2.less" first
bundles.Add(new Bundle("~/styles/css", new LessTransform()).Include("~/styles/component2.less", "~/styles/component1.less"));
Interestingly, it works if different files are imported in component1 and component2
For example, renaming "varibales" to "variables.less" in one file to differentiate the imports.
styles/component1.less
@import "variables.less"; // added extension here
body {
background:@color;
}
Any ideas? Been working on this for days..
Edit
Reasons for using this structure:
To separate less files in debug mode for easier debugging. Line number comments are not very helpful.
To concatenate and minify all less files for production.
Adding @import "variables" to every file is not ideal.
Tried including variables.less in .Include("variables.less", file-dependant-on-variables.less, ...) However, it does not work due to scoping issues mentioned here: Dotless - Can't reference less variable in separate file with MVC Bundling
A solution is concatenating the contents of every less file and parsing that concatenated file with Less. Find an example here: https://groups.google.com/forum/?fromgroups#!topic/dotless/j-8OP1dNjUY
However, in that case, a minified version of the parsed file seems unattainable.