forked from DIYgod/DPlayer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
72 lines (65 loc) · 2.17 KB
/
gulpfile.js
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
var gulp = require('gulp');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var cssNano = require('gulp-cssnano');
var rename = require('gulp-rename');
var babel = require("gulp-babel");
var sourcemaps = require("gulp-sourcemaps");
var browserSync = require('browser-sync').create();
// Launch the server
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: './'
},
startPath: '/demo'
});
});
// Move files
gulp.task('copy', function () {
gulp.src('src/font/*')
.pipe(gulp.dest('dist/font'));
gulp.src(['src/*.jpg', 'src/*.png'])
.pipe(gulp.dest('dist'));
});
// Build js files
gulp.task('compressJS', function() {
gulp.src(['src/*.js'])
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
.pipe(rename({
suffix: ".min"
}))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
// Build css files
gulp.task('compressCSS', function() {
gulp.src('src/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(cssNano())
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
// Watch files for changes & recompile
gulp.task('watch', function () {
gulp.watch(['src/*.js'], ['compressJS']);
gulp.watch(['src/*.scss'], ['compressCSS']);
gulp.watch('demo/*.html').on('change', browserSync.reload);
gulp.watch('demo2/*.html').on('change', browserSync.reload);
gulp.watch('demo/font/*', ['copy']);
});
// compile the project, including move font, compress js and scss, also be used to test
gulp.task('release', ['copy', 'compressJS', 'compressCSS']);
// Default task, running just `gulp` will move font, compress js and scss, launch server, watch files.
gulp.task('default', ['release', 'browser-sync', 'watch']);