如何在 gulp 中使用带有 uglify 的 coffescript?
How to use coffescript with uglify in gulp?
我有以下项目结构
assets
--javascripts
----controllers
------somefile.js
------somefile.js.coffee
我想编译 coffescripts 文件 (*.js.coffee
),然后合并所有文件,然后缩小它们。
var gulp = require('gulp')
var concat = require('gulp-concat')
var coffee = require('gulp-coffee');
var uglify = require('gulp-uglify')
var gulpFilter = require('gulp-filter');
gulp.task('scripts', function() {
var coffeeScriptFilesFilter = gulpFilter(['*.js.coffee']);
return gulp.src(['assets/javascripts/**/*'])
.pipe(coffeeScriptFilesFilter)
.pipe(coffee())
.pipe(coffeeScriptFilesFilter.restore())
.pipe(concat('application.js'))
.pipe(gulp.dest('public'))
.pipe(uglify().on('error', errorHandler));
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
});
不幸的是我遇到了这个错误
Error in plugin 'gulp-uglify'
Message:
/var/www/gulp/public/application.js: Unexpected token: operator (>)
Details:
fileName: /var/www/gulp/public/application.js
lineNumber: 3
没有 uglify
插件一切正常。结果是
console.log('hello!');
var lol = 'asd!';
(function() {
var test;
test = function() {
return "lol";
};
}).call(this);
uglify
插件可能正在尝试压缩 .js.coffee
文件,但我不知道具体原因。我该如何解决?
Uglify 失败,因为它遇到了 coffeescript。这表明 coffeeScriptFilesFilter 没有捕获所有 *.coffee.js 文件。
给定文件 foo.js.coffee 和 subdir/foo。js.coffee:
// this matches only foo.js.coffee
gulpFilter('*.js.coffee');
// this matches both
gulpFilter('**/*.js.coffee');
https://github.com/sindresorhus/gulp-filter#pattern
Accepts a string/array with globbing patterns which are run through multimatch
我有以下项目结构
assets
--javascripts
----controllers
------somefile.js
------somefile.js.coffee
我想编译 coffescripts 文件 (*.js.coffee
),然后合并所有文件,然后缩小它们。
var gulp = require('gulp')
var concat = require('gulp-concat')
var coffee = require('gulp-coffee');
var uglify = require('gulp-uglify')
var gulpFilter = require('gulp-filter');
gulp.task('scripts', function() {
var coffeeScriptFilesFilter = gulpFilter(['*.js.coffee']);
return gulp.src(['assets/javascripts/**/*'])
.pipe(coffeeScriptFilesFilter)
.pipe(coffee())
.pipe(coffeeScriptFilesFilter.restore())
.pipe(concat('application.js'))
.pipe(gulp.dest('public'))
.pipe(uglify().on('error', errorHandler));
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
});
不幸的是我遇到了这个错误
Error in plugin 'gulp-uglify'
Message:
/var/www/gulp/public/application.js: Unexpected token: operator (>)
Details:
fileName: /var/www/gulp/public/application.js
lineNumber: 3
没有 uglify
插件一切正常。结果是
console.log('hello!');
var lol = 'asd!';
(function() {
var test;
test = function() {
return "lol";
};
}).call(this);
uglify
插件可能正在尝试压缩 .js.coffee
文件,但我不知道具体原因。我该如何解决?
Uglify 失败,因为它遇到了 coffeescript。这表明 coffeeScriptFilesFilter 没有捕获所有 *.coffee.js 文件。
给定文件 foo.js.coffee 和 subdir/foo。js.coffee:
// this matches only foo.js.coffee
gulpFilter('*.js.coffee');
// this matches both
gulpFilter('**/*.js.coffee');
https://github.com/sindresorhus/gulp-filter#pattern
Accepts a string/array with globbing patterns which are run through multimatch