-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
72 lines (65 loc) · 2.18 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
const { src, dest, parallel, watch } = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const postcss = require('gulp-postcss')
const concat = require('gulp-concat')
const babel = require('gulp-babel')
const uglify = require('gulp-uglify')
const autoprefixer = require('autoprefixer')
const source = 'libraries/libraries/static'
// files will be copied both here _and_ above dir, too
const dist = 'libraries/static'
const settings = {
dist: {
css: dist + '/css/',
js: dist + '/js/',
},
src: {
// JavaScript src
exhibits: [source + '/js/exhibits.js'],
js: [source + '/js/src/*.js'],
// SASS src
styles: [
source + '/scss/main.scss'
, source + '/scss/exhibits.scss'
],
scss: [
source + '/scss/**/*.scss'
]
}
}
// tasks for each major set of files (main site CSS, main site JS, exhibits JS)
function allCSS() {
return src(settings.src.styles, { sourcemaps: true })
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(postcss([ autoprefixer() ]))
.pipe(dest(settings.dist.css))
.pipe(dest('libraries/' + settings.dist.css))
}
function exhibitsJS() {
return src(settings.src.exhibits, { sourcemaps: true })
.pipe(concat('exhibits.min.js'))
.pipe(babel({ presets: ['@babel/preset-env'] }))
.pipe(uglify())
.pipe(dest(settings.dist.js))
.pipe(dest('libraries/' + settings.dist.js))
}
function mainJS() {
return src(settings.src.js, { sourcemaps: true })
.pipe(concat('main.min.js'))
.pipe(babel({ presets: ['@babel/preset-env'] }))
.pipe(uglify({ output: { comments: 'some' } }))
.pipe(dest(settings.dist.js))
.pipe(dest('libraries/' + settings.dist.js))
}
// watch each main set of files & run its associated task
function defaultTask() {
watch(settings.src.exhibits, exhibitsJS)
watch(settings.src.js, mainJS)
watch(settings.src.scss, allCSS)
}
// expose all tasks
exports.js = mainJS
exports.css = allCSS
exports.exhibits = exhibitsJS
exports.build = parallel(allCSS, mainJS, exhibitsJS)
exports.default = defaultTask