我想将 JavaScript 文件与 Coffee-Script 文件分开!
这是我的当前文件结构:
engine
world
behaviour.coffee
behaviour.js
character
behaviour.coffee
behaviour.js
engine.coffee
engine.js
这是我更喜欢的结构:
src
engine
world
behaviour.coffee
character
behaviour.coffee
engine.coffee
和
dest
engine
world
behaviour.js
character
behaviour.js
engine.js
我的实际 gulp文件如下所示:
gulp = require 'gulp'
coffee = require 'gulp-coffee'
gulp.task 'all-coffee-files', ->
gulp.src './**/*.coffee'
.pipe coffee()
.pipe gulp.dest (file) ->
file.base
gulp.task 'watch', ->
gulp.watch './**/*.coffee', ['all-coffee-files']
为了实现拆分,我必须进行哪些编辑?
非常感谢!
答案 0 :(得分:1)
不熟悉coffescript语法,但以下内容应该有效:
gulp = require 'gulp'
coffee = require 'gulp-coffee'
gulp.task 'all-coffee-files', ->
gulp.src './src/**/*.coffee'
.pipe coffee()
.pipe gulp.dest('./dest/')
gulp.task 'watch', ->
gulp.watch './src/**/*.coffee', ['all-coffee-files']
这会在./src/
中提供所有内容,并将生成的.js
文件放在./dest/
中,同时保持目录结构不变。