1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| var gulp = require('gulp'); var connect = require('gulp-connect'); var babel = require('gulp-babel'); var sourcemaps = require('gulp-sourcemaps'); var rename = require('gulp-rename'); var uglify = require('gulp-uglify'); var less = require('gulp-less'); var cleanCss = require('gulp-clean-css'); var autoprefixer = require('autoprefixer'); var postCss = require('gulp-postcss'); var proxy = require('http-proxy-middleware');
gulp.task('connect', function() { connect.server({ root: 'dist', livereload: true, port: 9000, middleware: function(connect, opt) { return [ proxy('/api', { target: '127.0.0.1:3000', changeOrigin:true }) ] } }); });
gulp.task('html', function() { gulp.src('./src/*.html') .pipe(connect.reload()) .pipe(gulp.dest('./dist')); });
gulp.task('less', ['html'], function() { gulp.src('./src/css/*.less') .pipe(sourcemaps.init()) .pipe(less()) .pipe(postCss([autoprefixer({browsers: ['last 2 versions']})])) .pipe(gulp.dest('./dist/css')) .pipe(cleanCss()) .pipe(rename({extname: '.min.css'})) .pipe(sourcemaps.write('./')) .pipe(connect.reload()) .pipe(gulp.dest('./dist/css/min')) });
gulp.task('js',['html'] , function () { gulp.src('./src/js/*.js') .pipe(sourcemaps.init()) .pipe(babel({ presets: ['env'] })) .pipe(gulp.dest('./dist/js')) .pipe(uglify()) .pipe(rename({extname: '.min.js'})) .pipe(sourcemaps.write()) .pipe(connect.reload()) .pipe(gulp.dest('./dist/js/min')) });
gulp.task('img', function () { gulp.src('./src/img/*.*') .pipe(connect.reload()) .pipe(gulp.dest('./dist')); })
gulp.task('watch', function() { gulp.watch(['./src/*.html'], ['html']);
gulp.watch(['./src/js/*.js'], ['js']);
gulp.watch(['./src/css/*.less'], ['less']); });
gulp.task('default', ['connect', 'watch', 'js', 'less']);
|