我是 Browserify 的初学者。我尝试使用 Watchify(出于性能原因)和 Coffeeify 将它集成到 gulp.js 中。我尝试了至少五种我在 Google 中找到的或多或少不同的方法,其中最后一种是来自 gulp 文档的官方配方。
现在的问题是转换部分。我想使用 Coffeeify 来解析我的代码,该代码主要是用 CoffeeScript 编写的。
Coffeeify 成功解析了我的入口文件app.coffee
,但是当我./foo.coffee
从那里需要一个时,该文件似乎没有被转换,这自然会导致 Browserify 关于意外令牌等的解析错误。
有人知道如何解决这个问题吗?
这是我的 gulpfile 的相关部分,与上面的链接基本相同,只是添加了转换。
var gulp = require( 'gulp' );
var gutil = require( 'gulp-util' );
var browserify = require( 'browserify' );
var watchify = require( 'watchify' );
var coffeeify = require( 'coffeeify' );
var source = require( 'vinyl-source-stream' );
var b = watchify( browserify({
entries: [ './coffee/app.coffee' ],
extensions: [ '.coffee' ],
debug: true,
cache: false,
packageCache: false
}) );
b.transform( coffeeify ); // as described in the gulp docs
gulp.task( 'bundle', bundle );
b.on( 'update', bundle );
b.on( 'log', gutil.log );
function bundle() {
return b.bundle()
.on( 'error', gutil.log.bind( gutil, 'Browserify Error' ) )
.pipe( source( 'bundle.js' ) )
// I actually tried to pipe in coffeeify here (gulp-coffeeify as well), didn't help
.pipe( gulp.dest( './js' ) );
};