I am developing a Gulpfile
. Can it be made to restart as soon as it changes? I am developing it in CoffeeScript. Can Gulp
watch Gulpfile.coffee
in order to restart when changes are saved?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Keeping track of variable instances
I created gulper that is gulp.js cli wrapper to restart gulp on gulpfile change.
You can simply replace gulp with gulper.
Install nodemon globally:
npm i -g nodemon
And add in your .bashrc (or .bash_profile or .profile) an alias:
This will watch for file gulpfile.js and gulpfile.babel.js changes. (see Google)
P.S. This can be helpful for endless tasks (like
watch
) but not for single run tasks. I mean it uses watch so it will continue process even after gulp task is done. ;)try this code (only win32 platform)
I use a small shell script for this purpose. This works on Windows as well.
Press
Ctrl+C
to stop the script.Bash shell script:
Windows version:
watch.bat
You can create a
task
that willgulp.watch
forgulpfile.js
and simplyspawn
another gulp child_process.I used
yargs
in order to accept the 'main task' to run once we need to restart. So in order to run this, you would call:And to test, call either
touch gulpfile.js
ortouch a.css
to see the logs.Here's another version of @CaioToOn's reload code that is more in line with normal Gulp task procedure. It also does not depend on
yargs
.Require spawn and initilaize the process variable (
yargs
is not needed):The default gulp task will be the spawner:
Your watch task was probably your default gulp task. Rename it to
watch
and add agulp.watch()
for watching your gulpfile and run thedefault
task on changes:Now, just run
gulp
and it will automatically reload if you change your gulpfile!