-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·63 lines (54 loc) · 1.59 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const babel = require('babelify');
const browserify = require('browserify')
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const minify = require('gulp-minifier');
gulp.task('scss', () => {
return gulp.src('src/scss/main.scss')
.pipe(sass().on('error', sass.logError))
.on('error', swallowError)
.pipe(gulp.dest('src/css'))
.pipe(browserSync.stream())
});
gulp.task('es6', () => {
browserify('src/js/main.js')
.transform('babelify', {
presets: ['es2015']
})
.bundle()
.on('error', swallowError)
.pipe(source('main.js'))
.pipe(buffer())
.pipe(gulp.dest('src/build'));
});
gulp.task('serve', () => {
browserSync.init({
server: "./src"
});
gulp.watch("src/scss/**", ['scss']);
gulp.watch("src/js/**", ['es6']);
gulp.watch("src/js/build/**", ['es6']).on('change', browserSync.reload);
gulp.watch("src/*.html").on('change', browserSync.reload);
});
gulp.task('build', function() {
return gulp.src(['!src/js/**', 'src/**']).pipe(minify({
minify: false,
collapseWhitespace: true,
conservativeCollapse: true,
minifyJS: false,
minifyCSS: true,
getKeptComment: function (content, filePath) {
var m = content.match(/\/\*![\s\S]*?\*\//img);
return m && m.join('\n') + '\n' || '';
}
})).pipe(gulp.dest('docs'));
});
function swallowError (error) {
console.log(error.toString())
this.emit('end')
}
gulp.task('default', ['serve'], () => {
});