我正在尝试执行两项任务,即监视任务和构建任务。 watch 任务调用我的“coffee”任务,它将我的
.coffee
文件编译成 JavaScript。
构建任务基本上应该做同样的事情,除了我想将布尔值解析到函数中,以便我可以编译包括源映射的代码。
gulp = require 'gulp'
gutil = require 'gulp-util'
clean = require 'gulp-clean'
coffee = require 'gulp-coffee'
gulp.task 'clean', ->
gulp.src('./lib/*', read: false)
.pipe clean()
gulp.task 'coffee', (map) ->
gutil.log('sourceMap', map)
gulp.src('./src/*.coffee')
.pipe coffee({sourceMap: map}).on('error', gutil.log)
.pipe gulp.dest('./lib/')
# build app
gulp.task 'watch', ->
gulp.watch './src/*.coffee', ['coffee']
# build app
gulp.task 'build', ->
gulp.tasks.clean.fn()
gulp.tasks.coffee.fn(true)
# The default task (called when you run `gulp` from cli)
gulp.task 'default', ['clean', 'coffee', 'watch']
有人能解决我的问题吗?我在原则上做错了什么吗? 预先感谢。
coffee
任务不必是 gulp 任务。 只需将其设为 JavaScript 函数即可。
gulp = require 'gulp'
gutil = require 'gulp-util'
clean = require 'gulp-clean'
coffee = require 'gulp-coffee'
gulp.task 'clean', ->
gulp.src('./lib/*', read: false)
.pipe clean()
compile = (map) ->
gutil.log('sourceMap', map)
gulp.src('./src/*.coffee')
.pipe coffee({sourceMap: map}).on('error', gutil.log)
.pipe gulp.dest('./lib/')
# build app
gulp.task 'watch', ->
gulp.watch './src/*.coffee', =>
compile(false)
# build app
gulp.task 'build', ['clean'], ->
compile(true)
# The default task (called when you run `gulp` from cli)
gulp.task 'default', ['clean', 'build', 'watch']