gpt4 book ai didi

coffeescript - 如何将参数传递给 gulp 任务回调?

转载 作者:行者123 更新时间:2023-12-04 18:42:41 26 4
gpt4 key购买 nike

我正在尝试做两个任务,一个监视和构建任务。
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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com