当我第一次浏览我的coffeescript代码时,它运行正常。但是,当我对源代码进行更改并观察尝试重新运行捆绑时,coffeeify似乎想要针对我的javascript运行coffeescript - 基于我从gulp得到的这个错误:
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一起使用?
答案 0 :(得分:3)
将变换移到捆绑功能之外:
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();
}