我正试图在Gnu Make中实现这一点。
我正在Makefile中测试wc手表。
我有一个文件,每当检测到更改时都需要编译它,它应该在运行2个并行命令的规则中运行配方。一个编译css,另一个重新加载浏览器。
如果我使用cssnext --watch
的内置watch命令,我的设置会很好,但我想使用wc
这是代码
BIN := node_modules/.bin
all: assets/css/style.css
assets/css/style.css: sources/style.css
@mkdir -p $(@D)
@set -e ;
while true;
do
$(shell wc -c "sources/style.css")
$(BIN)/cssnext $^ $@& $(BIN)/instant 3000;
sleep 1;
done
当我做make all
时,它显示
"D:/Program Files (x86)/Git/bin/sh.exe": line 4: 343: command not found
•∙ listening on port 3000 and waiting for changes
我是GNU Make的新手,我无法理解它。
更新:如果我使用bash脚本。使用以下代码创建一个watchfile.sh
文件:
#!/bin/bash
clearline="b 33[2Kr"
command=$@
while sleep 1;
do
# watch each character change
eval "wc -c $command"
echo -n -e "$clearline"
done
然后用替换Makefile
中的代码
./watchfile.sh $^
$(BIN)/cssnext $^ $@& $(BIN)/instant 3000;
我在外壳中得到以下内容
•∙ listening on port 3000 and waiting for changes 344 sources/style.css
284 node_modules/.bin/cssnext
344 sources/style.css
263 assets/css/style.css
1235 total
我不知道为什么它也在看其他文件,我只指定了sources/styles.css
如果我在css文件中进行了更改,它会显示字符数的变化。但是源/style.css文件没有编译到目标。shell只显示wc命令一次又一次地切换。
我做了一个小改动,它反映在wcshell 中
322 sources/style.css
284 node_modules/.bin/cssnext
322 sources/style.css
263 assets/css/style.css
1191 total
但现在的问题是,它没有编译甚至没有重新加载浏览器。
另一个问题是,现在wc命令不会停止循环。即使在我做CTRL+C
之后。我必须关闭终端
此外,我更喜欢不使用watchfile.sh脚本,而是在Makefile中执行。
如果你坚持使用make,只需编写一个编译CSS等的Makefile。这就是make的作用,你运行make
,它会编译所有更改的内容。
要使编译自动化,可以使用watch
实用程序,该实用程序定期运行make
:
watch make
这应该可以满足你的需要。这个问题中的更多信息:有没有比";手表制造"?
我让它与Makefile+NPM一起工作。尽管我需要一个完整的Makefile解决方案。不管怎样,它现在起作用了。