I think you should better the less.render
function, see also: http://lesscss.org/usage/#programmatic-usage.
But indeed you can use the @import directive as already made clear by @seven-phases-max.
Example:
<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>
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…