Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

how to use less mixins file in my code?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...