在项目中使用gulp
安装gulp
npm install gulp -g
npm install gulp gulp-coffee gulp-concat --save-dev
配置
我的js第三方库是使用bower
来管理的,.bowerrc
{
"directory": "public/js/vendor"
}
gulp这样配置,暂时只用了coffee的编译,没有使用js的合并和混淆
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
gulp.task('coffee', function () {
gulp.src(['./public/js/**/*.coffee', '!./public/js/vendor/**'])
.pipe(coffee())
.pipe(gulp.dest('./public/js/'));
});
gulp.task('scripts', function () {
gulp.src(['./public/js/**/*.js', '!./public/js/vendor/**'])
.pipe(concat('all.js'))
.pipe(gulp.dest('./public/dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./public/dist'));
});
gulp.task('default', function() {
gulp.run('coffee');
// gulp.run('scripts');
gulp.watch(['./public/js/**/*.coffee', '!./public/js/vendor/**'], function () {
gulp.run('coffee');
});
if (0) {
gulp.watch(['./public/js/**/*.js', '!./public/js/vendor/**'], function () {
gulp.run('scripts');
});
}
});