作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试做两个任务,一个监视和构建任务。
watch 任务调用我的“咖啡”任务来编译我的 .coffee
文件转换成javascript。
构建任务基本上应该做同样的事情,除了我想将一个 bool 值解析到函数中,以便我可以编译包括源映射在内的代码。
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']
关于coffeescript - 如何将参数传递给 gulp 任务回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21976810/
我是一名优秀的程序员,十分优秀!