-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
47 lines (41 loc) · 1.27 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
const gulp = require('gulp')
const sourcemaps = require('gulp-sourcemaps')
const browserSync = require('browser-sync').create()
// browserify + babel => es6 in browser
gulp.task('js', () => {
const browserify = require('browserify')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
return browserify('src/js/index.js')
.transform('babelify')
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build'))
.pipe(browserSync.stream())
})
// postcss => css
gulp.task('css', () => {
const postcss = require('gulp-postcss')
const autoprefixer = require('autoprefixer')
const precss = require('precss')
return gulp.src('src/**/*.css')
.pipe(sourcemaps.init())
.pipe(postcss([autoprefixer, precss]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build'))
.pipe(browserSync.stream())
})
// browserSync server
gulp.task('server', () => {
browserSync.init({
server: './'
})
gulp.watch(['./src/**/*.js'], ['js'])
gulp.watch(['./src/**/*.css'], ['css'])
gulp.watch(['./src/**/*.html']).on('change', browserSync.reload)
})
gulp.task('build', ['js', 'css'])
// gulp.task('test', [''])