【发布时间】:2015-06-29 15:30:01
【问题描述】:
我正在尝试让这个在 Gnu Make 中工作。
我正在 Makefile 中测试 wc watch。
我有一个文件,只要检测到更改,就需要对其进行编译,并且它应该在运行 2 个并行命令的规则中运行配方。一个编译css,另一个重新加载浏览器。
如果我使用cssnext --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 命令一次又一次地循环。
我做了一个小改动,它反映在 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 中执行。
【问题讨论】:
-
为什么不直接使用 grunt 或 gulp 呢?这些看起来更适合您的需求。
-
我不想使用 grunt 或 gulp,我正在尝试让它与 Makefile 一起使用。
-
嗯,make 并不适合监视文件的变化和重建——它只构建一次然后退出。此外,wc 不是检查是否发生更改的可靠方法,尽管它可能在大多数情况下都有效。
-
@IbnSaeed 有什么特别的理由不使用提到的 grunt 或 gulp 等 easy2use 工具吗?
-
我使用 NPM 作为构建工具,它可以很好地满足我的所有需求。我正在用 Makefile 尝试一些新的东西。 Grunt 和 Gulp,当我们有 NPM 脚本时,我看不出它们有用的原因。
标签: css shell compilation makefile gnu-make