Skip to content

Instantly share code, notes, and snippets.

@xhsdnn
Created July 30, 2018 03:38
Show Gist options
  • Save xhsdnn/ca05df0cb0e3861bc0ee9f67010d13e1 to your computer and use it in GitHub Desktop.
Save xhsdnn/ca05df0cb0e3861bc0ee9f67010d13e1 to your computer and use it in GitHub Desktop.
基本任务即插件
const gulp = require("gulp");
const spritesmith = require("gulp.spritesmith"); // https://github.com/twolfson/gulp.spritesmith
const imagemin = require('gulp-imagemin');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
// 默认任务
gulp.task('default', function () {
// 生成 CSS Sprites
return gulp.src('pngs/*.png')
.pipe(spritesmith({
imgName: 'index.png',
cssName: 'index.css', // css/scss/less/stylus/json
imgPath: './images' + 'index.png'
}))
.pipe(gulp.dest('./images'));
});
// 编译scss/目录下的scss文件,并把编译完成的css文件保存到/css目录中
gulp.task('sass', function () {
gulp.src('./scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('./css'));
});
// 合并js/目录下得所有的js文件并输出到dist/目录,然后gulp会重命名、压缩合并的文件,输出到dist/目录
gulp.task('scripts', function () {
gulp.src('./js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('./dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment