-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
gulpfile.js
88 lines (80 loc) · 2.54 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const gulp = require('gulp')
const path = require('path')
const autoprefixer = require('autoprefixer')
const babelify = require('babelify')
const browserify = require('browserify')
const browsersync = require('browser-sync').create()
const buffer = require('vinyl-buffer')
const notifier = require('node-notifier')
const postcss = require('gulp-postcss')
const rename = require('gulp-rename');
const rimraf = require('rimraf')
const sass = require('gulp-sass')
const source = require('vinyl-source-stream')
const sourcemaps = require('gulp-sourcemaps')
const uglify = require('gulp-uglify')
const util = require('gulp-util')
gulp.task('clean', (cb) => {
rimraf('./dist', cb)
})
gulp.task('build', ['clean'], () => {
gulp.start('build:js', 'build:scss')
})
function showError(arg) {
notifier.notify({
title: 'Error',
message: '' + arg,
sound: 'Basso'
})
console.log(arg)
this.emit('end')
}
gulp.task('build:scss', () => {
return gulp.src(path.join('examples', 'assets', 'styles.scss'))
.pipe(sass({
outputStyle: 'nested',
precision: 10,
includePaths: ['.', 'node_modules'],
onError: showError
}).on('error', function(error) {
showError(error)
this.emit('end')
}))
.pipe(postcss([
autoprefixer({
browsers: ['last 2 versions', 'Firefox ESR', 'Explorer >= 9', 'Android >= 4.0', '> 2%']
})
]))
.pipe(gulp.dest(path.join('examples', 'assets')))
.pipe(browsersync.stream({match: '**/*.css'}))
})
gulp.task('build:js', () => {
return browserify({entries: path.join('src', 'parallax.js'), debug: false, standalone: 'Parallax'})
.transform("babelify", {presets: ["es2015"]})
.bundle()
.on('error', showError)
.pipe(source('parallax.js'))
.pipe(buffer())
.pipe(gulp.dest('dist'))
.pipe(rename('parallax.min.js'))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', showError)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
.pipe(browsersync.stream({match: path.join('**','*.js')}))
})
gulp.task('watch', ['build'], () => {
browsersync.init({
notify: false,
port: 9000,
server: {
baseDir: [path.join('examples', 'pages'), path.join('examples', 'assets'), 'dist'],
directory: true
}
})
gulp.watch(path.join('src', '*.js'), ['build:js'])
gulp.watch(path.join('examples', 'assets', '*.scss'), ['build:scss'])
gulp.watch(path.join('examples', 'pages', '*.html'), browsersync.reload)
})
gulp.task('default', ['watch'])