Trying to build LESS (less css) using a build script with nodeJS
Using node.js
var less = require('less')
,fs = require('fs');
fs.readFile('style.less',function(error,data){
data = data.toString();
less.render(data, function (e, css) {
fs.writeFile('style.css', css, function(err){
console.log('done');
});
});
});
Less to css via node script
The first works here, maybe You should
console.log(error)
in the readFile callback, most likely Your path is wrong and the file cant be opened.
Node.js + Express.js. How to RENDER less css?
Gosh, that stuff is very inconsistent in how the paths work, however I found out how you can get it to work.
The first problem is with your paths, both compiler
and staticProvider
, compiler needs to use /public
and is will hook into all requests below that. If you don't do that, the compiler will try to use a path like /public/stylo/stylo
.
The second problem lies with the @import
in main.less
file and the fact that less compiler is stupid and does not handle relative imports.
Using @import "/public/stylo/goodies.css";
in your main.less
will make it work.
Filed a Bug for the relative path issue with less
:
https://github.com/cloudhead/less.js/issues/issue/177
How to compile lesscss using node.js
You can install the LESS compiler directly from npm
.
- Install
node.js
. Go to this page and download the installer for your platform.
If you're on Windows, download the.msi
; if you are on OSX, download the.pkg
file. Whenever possible, download the 64-bit version (unless your system is running only 32-bit hardware and software). If you are on Linux and you want to use package managers, see this page. - Once you have
node.js
installed, you should also havenpm
, which isnode.js
Package Manager. You can open a terminal/console and runnpm -v
to make sure everything is installed correctly. Eventually, you can install the LESS compiler by simply executing:
npm install -g less
(note: on OSX and Linux you may need to run this with sudo: sudo npm install -g less
).
The LESS compiler will then be available as the lessc
command. See examples here.
PS: Some GUIs also exist for simplifying working with lessc
. Google "less gui windows/mac/linux" to see many results, like this one for Mac.
Related Topics
How to Use a SASS $Variable Across Multiple Pages Using @Use
Wget Downloads CSS @Import, But Ignores Files Referenced Within Them
How to Offset Line-Height Base Line
Reactjs Align Material-Ui Elements Horizontally
How to Resolve The CSS Warnings for Browser Specific Selectors in Bootstrap 3
CSS Color Rendering Different in Safari
How to Remove The Styles from The Pseudo Element -Internal-Input-Suggested
Font-Awesome Class with Multiple Different Icons
How to Make Input Buttons Look Exactly The Same in All Browsers
"_Msg_@@Extension_Id_" Doesn't Work and Webfonts Don't Load
Applying Borders to a Single Table Cell When Using Border-Collapse
CSS Transition (Height Property) - Can't Get It to Roll from Bottom
Right-Align The Contents of a Facebook Like-Button Iframe
Slide Flickering with CSS Transitions
How to Create Tags Like Stackoverflow with Text Styling