Automatically concatenating files using Watchr

穿精又带淫゛_ 提交于 2019-12-08 10:02:40

问题


I have a bunch of JS files that I split up, but want to concatenate automatically (so I don't define a bunch of files in HTML). Right now, I copied the command from Twitter Bootstrap. Makefile:

scripts:
 cat scripts/*.js > public/scripts/scripts.js

watchScripts: 
  watchr -e "watch('scripts/.*\.js') {system 'make scripts'}"

However, I've found watchr to be very inconsistent (on Mac OS X 10.8)

  1. Sometimes when I save a js file, it doesn't run make scripts. Other times, it does.
  2. One time, it just kept running make scripts continuously after a single save.
  3. Sometimes, it will run the command a few seconds after the last save.

Am I doing something wrong? I'm working using node.js and not Ruby, so are there any node.js command-line alternatives? The same issues seem to happen to me when I try make watch in Bootstrap.

Aside question: I have another watch command:

stylus -w -u nib styles/styles.styl -o public/styles

How can I run two watch commands in a single Makefile command? IE make watch will watch both .styl files to compile, and .js files to concatenate. Right now I'm opening up two terminals, for each watch command, but I'd prefer a single one.


回答1:


Have you tried brunch? It's really great for this kind of stuff when working on node.js. You can just use a skeleton or set it up manually and have a script your whole directory, merging and compiling on the go.



来源:https://stackoverflow.com/questions/12045365/automatically-concatenating-files-using-watchr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!