简体   繁体   中英

Save the .css file generated by less.js

I know that it is not recommended to use less.js to compile the .css on a production website, however I had to do that for a reason instead of using third party compilers (which I find more than useful for general purpose compiling). The question is how do I reach the css styles the less.js compiler generated (to eg save them in a different file)? Below is how I had to compile my less files:

<link rel="stylesheet/less" type="text/css" href="assets/less/styles.less" />

<script>
  var less = {
    modifyVars: {
      '@brand-primary': 'yellow'
    }
  };
</script>

<script src="less.min.js"></script>

You can not save the generated .css file via browser. You have to do this on the server side via PHP or Node.js:

import fs   from 'fs';
import less from 'less';

less.render('.class { width: (1 + 1) }', (error, output) => {
  fs.writeFile('/path/to/file.css', output)
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM