![]()
从头编写HTML\CSS\JavaScript是上个世纪的事情了,如今的JavaScript都是通过CoffeeScript这样的支持句法缩写的编辑器写成的。如果你希望写完JavaScript能够一个工具完成代码清理优化工作,Gulp 就是你的不二之选,GulpJS类似Ant或Maven之于Java。
示例代码:
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var sourcemaps = require('gulp-sourcemaps');
var del = require('del');
var paths = {
scripts: ['clIEnt/js/**/*.coffee', '!client/external/**/*.coffee'],
images: 'client/img/**/*'
};
// Not all tasks need to use streams
// A gulpfile is just another node program and you can use all packages available on npm
gulp.task('clean', Function(cb) {
// You can use multiple globBing patterns as you would with `gulp.src`
del(['build'], cb);
});
gulp.task('scripts', ['clean'], function() {
// MiNify and copy all JavaScript (except vendor scripts)
// with sourcemaps all the way down
return gulp.src(paths.scripts)
.pipe(sourcemaps.init())
.pipe(coffee())
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/js'));
});
// Copy all static images
gulp.task('images', ['clean'], function() {
return gulp.src(paths.images)
// Pass in options to the task
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest('build/img'));
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.images, ['images']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'scripts', 'images']);
发布于 2017-08-20 02:54:10 | 192 次阅读
发布于 2017-07-24 15:46:14 | 147 次阅读
发布于 2017-09-05 11:06:29 | 176 次阅读
发布于 2017-05-26 21:54:59 | 175 次阅读
发布于 2017-06-25 21:48:27 | 181 次阅读
发布于 2017-03-25 13:28:26 | 119 次阅读
发布于 2017-04-06 09:58:44 | 156 次阅读
发布于 2017-02-26 03:19:01 | 228 次阅读
发布于 2017-04-06 13:26:33 | 181 次阅读
发布于 2017-03-29 03:56:00 | 188 次阅读
发布于 2016-01-25 10:04:02 | 208 次阅读
发布于 2016-01-15 03:24:15 | 458 次阅读
发布于 2016-01-15 21:55:59 | 2708 次阅读
发布于 2016-01-09 21:14:17 | 261 次阅读
发布于 2016-01-09 22:28:22 | 265 次阅读
发布于 2015-12-31 13:14:59 | 408 次阅读
发布于 2015-12-23 02:56:36 | 398 次阅读
发布于 2015-12-17 21:28:09 | 374 次阅读
发布于 2015-12-13 21:26:04 | 254 次阅读
发布于 2015-12-11 05:28:43 | 342 次阅读