使用gulp+;browserify&x2B;watchify&x2B;coffeeify尝试重新传输javascript而不是coffeescript
当我第一次浏览我的coffeescript代码时,它运行良好。但是,当我更改源代码并watchify尝试重新运行捆绑包时,coffeeify似乎想针对我的javascript运行coffeescript-基于gulp的错误:使用gulp+;browserify&x2B;watchify&x2B;coffeeify尝试重新传输javascript而不是coffeescript,coffeescript,gulp,browserify,watchify,Coffeescript,Gulp,Browserify,Watchify,当我第一次浏览我的coffeescript代码时,它运行良好。但是,当我更改源代码并watchify尝试重新运行捆绑包时,coffeeify似乎想针对我的javascript运行coffeescript-基于gulp的错误: events.js:72 throw er; // Unhandled 'error' event ^ SyntaxError: reserved word 'var' while parsing file: /Volumes/dev/app/f
events.js:72
throw er; // Unhandled 'error' event
^
SyntaxError: reserved word 'var' while parsing file: /Volumes/dev/app/frontend/editor/main.coffee
这是我的Gulpfile:
var gulp = require('gulp');
var gutil = require('gulp-util');
var watchify = require('watchify');
var browserify = require('browserify');
var coffeeify = require('coffeeify');
var source = require('vinyl-source-stream');
var stringify = require('stringify');
var _ = require('underscore');
var browserifyOpts = {
basedir: "./app/frontend/editor",
debug: true,
extensions: ['.coffee'],
entries: ['./main.coffee']
};
var opts = _.extend({}, watchify.args, browserifyOpts);
var bundler = browserify(opts);
var watch = watchify(bundler);
watch.on('update', bundle);
watch.on('log', gutil.log);
function bundle() {
var b = function() {
return bundler
.transform(stringify(['.html']))
.transform('coffeeify')
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('app/assets/javascripts/bundles'));
};
return b();
}
gulp.task('default', ['browserify-main']);
gulp.task('browserify-main', bundle);
如何使捆绑过程也能与watchify一起工作?将您的转换移到捆绑功能之外:
var bundler = browserify(opts);
bundler.transform(stringify(['.html']))
bundler.transform('coffeeify')
var watch = watchify(bundler);
watch.on('update', bundle);
watch.on('log', gutil.log);
function bundle() {
var b = function() {
return bundler
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('app/assets/javascripts/bundles'));
};
return b();
}
成功了!非常感谢。我不知道为什么。。。解释为什么会有不同,容易吗?