如何从命令行一次编译多个文件?(How to compile multiple files at once from command line?)

我从lesscss开始,我不想使用一些GUI工具,只是命令行。

我的结构如下 根 - - 减 --- css

我想将所有较少的文件编译到css文件夹。 怎么做到这一点?

提前致谢!

I'm beginning with lesscss and I don't want to use some GUI tools but command line only.

My structure is the following root --- less --- css

I would like to compile all less files to the css folder. How to achieve this ?

Thanks in advance!

最满意答案

默认情况下,可以通过运行npm install less的命令行编译器(lessc)将单个Less文件编译为single.css文件。

根据项目结构和Less文件,您应该选择如何编译所有Less文件。

当您想将每个Less文件编译成CSS文件时,您可以编写一些命令行脚本来迭代您的文件并通过调用lessc编译器来编译每个文件。 可能你最好考虑使用一个任务运行器,例如gulp-less或grunt-contribe-less。

在大多数情况下,不同文件中的Less代码是相关的,一个文件定义变量,mixins在其他文件中使用,依此类推。 对于这种情况,您可以创建一个project.less文件来导入其他文件:

project.less: @import "variable.less"; @import "theme.less";

现在你必须只编译project.less 。 您可以通过运行lessc project.less project.css来完成此操作。 上面的命令再次将Less代码编译成单个CSS。

要回答你的问题只是理论问题,当你的Less文件不依赖于彼此而你只想将它们全部编译成一个CSS文件时,你可以运行(在linux / unix上):

paste -s less/*.less | lessc - > css/project.css

By default the command line compiler (lessc) which can be installed by running npm install less compiles a single Less file into a single.css file.

Depending of the structure of your project and Less files you should choose how to compile all your Less files.

When you want to compile each Less file into a CSS file you can write some command line scripting that iterate over your files and compile each by invoking the lessc compiler. Probably you should better consider to use a task runner for instance gulp-less or grunt-contribe-less.

In most situations the Less code in the different files is related, one file defined variable and mixins used in other files and so on. For that situation you can create a single project.less file which imports the other files:

project.less: @import "variable.less"; @import "theme.less";

Now you will have to compile only the project.less. You can do this by running lessc project.less project.css. The preceding command compiles your Less code into a single CSS again.

To answer you question only theoretical, when your Less files do not depend on each other and your only want to compile them all into a single CSS file, you can run (on linux/unix):

paste -s less/*.less | lessc - > css/project.css

更多推荐