-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
69 lines (60 loc) · 1.99 KB
/
gulpfile.babel.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
import browserify from 'browserify'
import riotify from 'riotify'
import gulp from 'gulp'
import uglify from 'gulp-uglify'
import cssmin from 'gulp-cssmin'
import sourcemaps from 'gulp-sourcemaps'
import sass from 'gulp-sass'
import autoprefixer from 'gulp-autoprefixer'
import source from 'vinyl-source-stream'
import buffer from 'vinyl-buffer'
import browserSync from 'browser-sync'
// Path configuration...
const entryPoint = './src/bundle.js'
const browserDir = './build'
const sassWatchPath = './src/styles/**/*.scss'
const jsWatchPath = './src/**/*.js'
const tagWatchPath = './src/tags/**/*.tag'
const htmlWatchPath = './**/*.html'
gulp.task('js', () => {
return browserify(entryPoint, {debug: true, extensions: ['es6']})
.transform('babelify', {presets: ['es2015']})
.transform('riotify')
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// .pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/js/'))
.pipe(browserSync.reload({stream: true}))
})
gulp.task('browser-sync', () => {
const config = {
server: {baseDir: browserDir},
open: false,
}
return browserSync(config)
})
gulp.task('sass', () => {
return gulp.src(sassWatchPath)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(cssmin())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/css'))
.pipe(browserSync.reload({stream: true}))
})
gulp.task('watch', () => {
gulp.watch(jsWatchPath, ['js'])
gulp.watch(tagWatchPath, ['js'])
gulp.watch(sassWatchPath, ['sass'])
gulp.watch(htmlWatchPath, function () {
return gulp.src('')
.pipe(browserSync.reload({stream: true}))
})
})
gulp.task('default', ['js', 'sass', 'watch', 'browser-sync'])