【发布时间】:2015-02-17 16:49:39
【问题描述】:
晚安,
我对 makefiles 完全陌生,并制定了一个非常适合我们需求的文件,但我并不完全满意。我们使用 bootstrap3 并且有大约 40 个不同颜色设置的客户。这就是为什么我们需要编译 40 个稍微不同的 css 文件。到现在为止,我们有如下文件结构
- less/customer1.less
- css/customer1.css
- color/customer.less 包含引导变量文件
customer1.less 包含
@variables: 'myCompany/color/customer1'; //this is forwarded to where bootrstrap loads the variables template
@import "bootstrap";
@import 'myCompany/modifications';
我们的makefile
SOURCES = $(shell ls less/*.less)
# Files we don't want to be build
SOURCES := $(filter-out less/bootstrap.less, $(SOURCES))
SOURCES := $(filter-out less/a11y.less, $(SOURCES))
TARGETS = $(patsubst less/%.less,css/%.css,$(SOURCES))
DEPEND = $(patsubst less/%.less,make/%.d,$(SOURCES))
css/%.css: less/%.less
# First building dependency files
lessc -M $< $@ > 'make/$*.d'
# Then building CSS and sourcemap
lessc -s $< > $@ --source-map=map/$*.css.map --source-map-basepath=map --clean-css
-include $(DEPEND)
all: $(TARGETS)
打电话
$ make all
在 make/ 中创建 Makefile,在 css/ 中创建 CSS/在 map/ 中创建 CSS 源映射,并期望 LESS 在 less/ 中。
这可行,但我们需要为每个客户手动创建 customerX.less,即使唯一的区别是分配的配色方案/变量文件。 如果有此 customerX 的文件,Make 应查看颜色文件夹,然后在 less 目录中创建(但不覆盖!)customerX.less。
这里有任何制作大师知道如何使用 make 做到这一点吗?
【问题讨论】:
-
上面的makefile好像还是有问题。对于customer1,一切都很好。但它不会续订customer2。该行为取决于包含声明中的顺序。如果我首先包含 customer2 一切都适用于该客户,但随后 customer1 丢失。有人知道为什么吗?已经尝试设置一个包含依赖项的新变量 DEPEND。尽管如此,依赖顺序也存在同样的问题。
-
发生这种情况是因为我调用了“make”而不是“make all”。我已经改进了上面的代码。