我正在努力让这个在 Gnu Make 中工作。
我正在 Makefile 中测试 wc watch。
我有一个文件,只要检测到更改就需要对其进行编译,并且它应该在运行 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\033[2K\r"
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;
我在 shell 中得到以下内容
•∙ 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 文件中进行更改,它会显示字符数发生变化。但是 source/style.css 文件没有编译到目标。 shell 只显示 wc 命令一遍又一遍。
我做了一个小改动,它反射(reflect)在 wc shell 中
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,只需编写一个 Makefile 来编译您的 CSS 等 - 这就是 make 的用途,您运行 make
并编译所有已更改的内容。
要使编译自动进行,您可以使用 watch
实用程序,它会定期运行 make
:
watch make
这应该可以满足您的需求。此问题的更多信息:Is there a smarter alternative to "watch make"?
关于css - 如何在 Makefile 中使用 wc 来监视更改并在每次更新时运行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29789685/