how to use less mixins file in my code?

南笙酒味 提交于 2019-12-13 08:40:05

问题


here is 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);
        }

I have a mixins less file here http://lessprefixer.com/ for shorthand css3 prefix, how I setup it into my parse less code?


回答1:


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.



来源:https://stackoverflow.com/questions/27445979/how-to-use-less-mixins-file-in-my-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!