Setting up Sublime Text and less autocompile in Windows with the less2css plugin can be tricky because most solutions are geared to *nix. Most solutions I found for this include using a random git repo and executing code from them which I don’t trust.
Here are the steps I used:
- Install node using the Windows installer: https://nodejs.org/en/
- Open a command prompt and navigate to the folder that contains node.exe, you chose this when installing node. Mine is “C:\Program Files\nodejs\”
- Install less from command line by running this command:
npm install less - Install less cleanup plugin by running this command:
npm install less-plugin-clean-css - Navigate to the less bin folder in explorer, mine is: “C:\Program Files\nodejs\node_modules\less\bin\”
- There should be a lessc file in there, if not follow the steps above until there is one
- Create a new text file in the less bin folder called “lessc.cmd”
- Edit lessc.cmd in a text editor and enter the following line:
@”C:\Program Files\nodejs\node.exe” “C:\Program Files\nodejs\node_modules\less\bin\lessc” %*
- Note: Change the paths to match your local system
- Add lessc to the path environment variable.
- My entry looks like this:
;C:\Program Files\nodejs\node_modules\less\bin - If you have an issue with your path variable being longer than the default 1024 character limit, I recommend using SetEnv: http://www.codeproject.com/Articles/12153/SetEnv
- My entry looks like this:
- Open a new command prompt and type “lessc”, you should see the various commandline options listed along with some helpful information.
- If you see
‘lesscc’ is not recognized as an internal or external command,
Verify each step above to make sure that they all completed successfully. Also make sure to open a NEW command prompt after setting the path variable.
- If you see
- In Sublime Text, open the package manager with ctrl+shift+p, type install, and run Package Control: Install Package
- When the prompt comes up type less2css and hit enter
- Open a .less file for editing and hit save, it should automatically generate the .css file for you now