-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.babel.js
53 lines (46 loc) · 1.54 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
import gulp from 'gulp'
import sass from 'gulp-sass'
import autoprefixer from 'gulp-autoprefixer'
import uglify from 'gulp-uglify'
import hash from 'gulp-hash'
import del from 'del'
import pump from 'pump'
const staticDir = 'themes/osprey/static/',
scriptsDir = `${staticDir}scripts/`,
stylesDir = `${staticDir}styles/`
// Minify JS
gulp.task('js', (cb) => {
// Delete old JS files
del([`${scriptsDir}*-*.min.js`])
// Minifiy and hash JS files
pump([
gulp.src(`${scriptsDir}src/*.js`),
uglify(),
hash({ template: '<%= name %>-<%= hash %>.min<%= ext %>' }),
gulp.dest(scriptsDir),
hash.manifest('cachedAssets.json'), // Create hash map
gulp.dest('data/') // Put hash map in data folder
], cb)
})
// Compile and minify SCSS files to CSS
gulp.task('scss', (cb) => {
// Delete old CSS files
del([`${stylesDir}main-*.min.css`])
// Compile and hash CSS files
pump([
gulp.src(`${stylesDir}scss/main.scss`),
sass({ outputStyle: 'compressed' }),
autoprefixer({ browsers: ['last 10 versions'] }),
hash({ template: '<%= name %>-<%= hash %>.min<%= ext %>' }),
gulp.dest(stylesDir),
hash.manifest('cachedAssets.json'), // Create hash map
gulp.dest('data/') // Put hash map in data folder
], cb)
})
// Watch scripts and styles folders for changes
gulp.task('watch', ['js', 'scss'], () => {
gulp.watch(`${scriptsDir}src/*.js`, ['js']),
gulp.watch(`${stylesDir}scss/*.scss`, ['scss'])
})
// Set watch as default task
gulp.task('default', ['watch'])