-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
109 lines (96 loc) · 2.93 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const gulp = require('gulp')
const debug = require('gulp-debug')
const plumber = require('gulp-plumber')
const notify = require('gulp-notify')
const sourcemaps = require('gulp-sourcemaps')
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer');
const gcmq = require('gulp-group-css-media-queries')
const cleanCSS = require('gulp-clean-css')
const rollup = require('gulp-better-rollup')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const browserSync = require('browser-sync').create()
const pkg = require('./package.json')
const rollupConfig = () => {
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const babel = require('rollup-plugin-babel')
return {
rollup: require('rollup'),
plugins: [
resolve(),
commonjs(),
babel({
babelrc: false,
runtimeHelpers: true,
externalHelpers: true,
presets: ['@babel/preset-env']
}),
]
}
}
/**
* Handle errors and alert the user.
*/
const handleErrors = (r) => {
notify.onError('ERROR: <%= error.message %>\n')(r)
}
gulp.task('scss', () => {
return gulp.src('src/Resources/scss/*.scss')
.pipe(debug())
.pipe(plumber(handleErrors))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gcmq())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('css'))
.pipe(browserSync.stream({ match: '**/*.css' }))
})
gulp.task('babel', () => {
return gulp.src('src/Resources/js/*.js')
.pipe(debug())
.pipe(plumber(handleErrors))
.pipe(sourcemaps.init())
.pipe(rollup(rollupConfig(), {
extend: true,
format: 'iife',
globals: pkg.globals || {}
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('js'))
});
gulp.task('minify:js', () => {
return gulp.src(['js/*.js', '!js/*.min.js'])
.pipe(debug())
.pipe(plumber())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('js'))
})
gulp.task('minify:css', () => {
return gulp.src(['css/*.css', '!css/*.min.css'])
.pipe(debug())
.pipe(plumber(handleErrors))
.pipe(cleanCSS())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('css'))
})
gulp.task('copy', (done) => {
gulp.src(['node_modules/selectize/dist/css/selectize.css', 'node_modules/selectize/dist/js/standalone/selectize*.js'])
.pipe(gulp.dest('libs/selectize'))
done()
})
gulp.task('watch', () => {
browserSync.init({
open: false,
proxy: 'http://awebooking.local',
})
gulp.watch('src/Resources/scss/**/*.scss', gulp.series(['scss']))
gulp.watch('src/Resources/js/**/*.js', gulp.series(['babel']))
})
gulp.task('js', gulp.series(['babel', 'minify:js']))
gulp.task('css', gulp.series(['scss', 'minify:css']))
gulp.task('default', gulp.series(['css', 'js']))