如何在我的代码中使用更少的mixins文件? [英] how to use less mixins file in my code?
问题描述
这是我的代码
var parser = window.less.Parser();
try{
parser.parse(aztp_css_editor.getValue(), function(error, result){
if(!error){
alert(result.toCSS());
}else{
alert(error);
}
});
}catch(error){
alert(error);
}
我在这里有一个mixins较少的文件 http://lessprefixer.com/用于简写css3前缀,如何设置放入我解析较少的代码中?
I have a mixins less file here http://lessprefixer.com/ for shorthand css3 prefix, how I setup it into my parse less code?
推荐答案
I think you should better the less.render
function, see also: http://lesscss.org/usage/#programmatic-usage.
但是实际上,您可以使用@import指令,如@ seven-phases-max所阐明的那样.
But indeed you can use the @import directive as already made clear by @seven-phases-max.
示例:
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/2.1.0/less.min.js"></script>
<script>
less.render('@import "test.less"; p {color: @red; }', {'include-path': 'test/'})
.then(function(output) {
// output.css = string of css
// output.map = string of sourcemap
// output.imports = array of string filenames of the imports referenced
console.log(output.css);
},
function(error) {
});
</script>
当test.less在与包含代码的html相同的路径中可用时,以上代码编译良好(结果为output.css
).您也可以在导入中使用路径,'@import "path/test.less";
我没有发现设置include-path有任何作用.
The above compiles well (results in output.css
) when test.less is available in the same path as the html which contains the code. You can also use a path in your import, '@import "path/test.less";
I did not found that setting include-path has any effect.
这篇关于如何在我的代码中使用更少的mixins文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!