如何在 node.js 和 Windows 之上安装和运行lessc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16492940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install and run lessc on top of node.js and Windows?
提问by curious1
Hi I am learning LESS and I would like to install lessc on my Windows 7.
嗨,我正在学习 LESS,我想在我的 Windows 7 上安装 lessc。
Following this tutorial http://verekia.com/less-css/dont-read-less-css-tutorial-highly-addictive
按照本教程http://verekia.com/less-css/dont-read-less-css-tutorial-highly-上瘾
The first step is I dowloaded and installed node.js (node-v0.10.5-x64.msi).
第一步是我下载并安装了 node.js (node-v0.10.5-x64.msi)。
Then in a console, I ran
然后在控制台中,我跑了
npm install less -g
I got the following:
我得到以下信息:
npm http GET https://registry.npmjs.org/less
npm http 304 https://registry.npmjs.org/less
npm http GET https://registry.npmjs.org/ycssmin
npm http 304 https://registry.npmjs.org/ycssmin
C:\Users\Me\AppData\Roaming\npm\lessc -> C:\Users\Me\AppData\Roaming\npm\node_modules\less\bin\lessc
[email protected] C:\Users\Me\AppData\Roaming\npm\node_modules\less
+-- [email protected]
Then I ran the following in the same console:
然后我在同一个控制台中运行以下命令:
lessc style.less > style.css
But I got
但我得到了
'lessc' is not recognized as an internal or external command, operable program or batch file.
'lessc' 不是内部或外部命令,也不是可运行的程序或批处理文件。
I am not sure where I got wrong. I googled but it seems there is too much stuff, not sure which one is right. Did many tests without any success.
我不确定我哪里出错了。我用谷歌搜索,但似乎有太多的东西,不知道哪一个是对的。做了很多测试都没有成功。
Could someone tell me how to do it or give me a pointer to some place with detailed and latest install info for Windows?
有人能告诉我怎么做,或者给我一个指向某个地方的指针,其中包含 Windows 的详细和最新安装信息?
采纳答案by curious1
In a console, run the following:
在控制台中,运行以下命令:
node C:\Users\Me\AppData\Roaming\npm\node_modules\less\bin\lessc style.less > style.css
style.lessmust be in the console's directory.
style.less必须在控制台的目录中。
回答by tudo75
to get lessc working you have to add
为了让lessc工作,你必须添加
C:\Users\Me\AppData\Roaming\npm
C:\Users\Me\AppData\Roaming\npm
to the path
到路径
回答by liza
step 1: npm install less -g
第1步: npm install less -g
step 2: npm i less --save-dev
第2步: npm i less --save-dev
回答by exaviore
I guess you could add the bin folder in system properties -> advanced ->environment variables and append the whole path to the bin folder by edited the Path variable.
我想您可以在系统属性 -> 高级 -> 环境变量中添加 bin 文件夹,并通过编辑 Path 变量将整个路径附加到 bin 文件夹。
回答by MinchinWeb
If you just installed node.js, the windows PATH variable won't be updated within any running CMD windows. Try closing CMD and reopening it!
如果你刚刚安装了 node.js,windows PATH 变量将不会在任何正在运行的 CMD 窗口中更新。尝试关闭 CMD 并重新打开它!
回答by zhuangr
If you are using windows, don't forget to open the command line console as an administrator.
如果您使用的是 Windows,请不要忘记以管理员身份打开命令行控制台。
回答by Umesh Patil
Well, you must have NodeJS installed on your machine, use this linkto download and install it.
好吧,您的机器上必须安装了 NodeJS,使用此链接下载并安装它。
Once installed make sure to restart your machine. Then check whether it is properly installed by running "node -v" and "npm -v" in CMD.
安装后,请确保重新启动机器。然后通过在CMD中运行“node -v”和“npm -v”来检查它是否安装正确。
Once that is done run "npm install less -g" and you are ready to compile your less files.
完成后运行“npm install less -g”,您就可以编译您的 less 文件了。
Just go into the directory where your files are and run "lessc style.less style.css"
只需进入文件所在的目录并运行“lessc style.less style.css”
More can be found on this link.
可以在此链接上找到更多信息。
回答by Mikey Nichols
I fixed this issue by using Node Version Manager (nvm) to install and use the latest version of Node.js
我通过使用节点版本管理器 (nvm) 安装和使用最新版本的 Node.js 解决了这个问题
nvm install latestnvm use 12.4.0
nvm install latestnvm use 12.4.0
After that I navigated to my project folder and typed: npm install less -gand thennpm i less --save-dev
之后,我导航到我的项目文件夹并输入:npm install less -g然后npm i less --save-dev
Finally I typed lessc less/index.less css/index.cssto compile my less.
最后我输入lessc less/index.less css/index.css编译我的less。
回答by Ravindra
After spending around number of hours hunting around to compile less files, I got very simple answer:
在花了大约几个小时寻找编译更少的文件后,我得到了非常简单的答案:
- download node-v0.10.26-x64.msi for windows users -> install it -> then
- go to any folder(in command prompt) where *.less files are located and run the command "lessc styles.lsss > styles.css". (Example: in command prompt, less is my less folder where *.less files exist) D:\less>lessc styles.less > styles.css
- now you will get styles.css files created automatically. Open and see styles.css file
- 为 Windows 用户下载 node-v0.10.26-x64.msi -> 安装 -> 然后
- 转到 *.less 文件所在的任何文件夹(在命令提示符下)并运行命令“lessc styles.lsss > styles.css”。(例如:在命令提示符中,less 是我的 less 文件夹,其中存在 *.less 文件) D:\less>lessc styles.less > styles.css
- 现在您将获得自动创建的 style.css 文件。打开并查看styles.css 文件

