forked from beccasafan/pgm-multiloc
-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
161 lines (144 loc) · 4.08 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
var browserify = require('browserify')
var buffer = require('vinyl-buffer')
var concat = require('gulp-concat')
var gulp = require('gulp')
var gutil = require('gutil')
var htmlmin = require('gulp-htmlmin')
var plumber = require('gulp-plumber')
var rename = require('gulp-rename')
var sass = require('gulp-sass')
var source = require('vinyl-source-stream')
var sourcemaps = require('gulp-sourcemaps')
var tsify = require('tsify')
var uglify = require('gulp-uglify')
var watchify = require('watchify')
var config = {
'nodeModules': './node_modules/',
'src': {
'html': 'src/',
'styles': {
'app': 'src/styles/app/',
'vendor': 'src/styles/vendor/'
},
'scripts': {
'app': 'src/scripts/app/',
'vendor': 'src/scripts/vendor/'
}
},
'output': {
'html': 'docs/',
'styles': 'docs/styles/',
'scripts': 'docs/scripts/'
},
'externalLibs': require('./package.json')['browserify-shim']
}
var onError = function (err) {
gutil.log(err.message)
this.emit('end')
}
gulp.task('styles/lib', function () {
return gulp
.src([`${config.src.styles.vendor}*.scss`])
.pipe(plumber({ 'errorHandler': onError }))
.pipe(sourcemaps.init())
.pipe(sass({
'includePaths': [`${config.nodeModules}foundation-sites/scss/`],
'outputStyle': 'compressed',
'errorHandler': onError
}))
.pipe(concat('vendor.css'))
.pipe(rename({ 'suffix': '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${config.output.styles}`))
})
gulp.task('styles/lib-watch', ['styles/lib'], function () {
gulp.watch(`${config.src.styles.vendor}*.scss`, [ 'styles/lib' ])
})
gulp.task('styles', function () {
return gulp
.src([`${config.src.styles.app}app.scss`])
.pipe(plumber({ 'errorHandler': onError }))
.pipe(sourcemaps.init())
.pipe(sass({
'includePaths': [`${config.src.styles.app}`],
'outputStyle': 'compressed'
}))
.pipe(rename({ 'suffix': '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${config.output.styles}`))
})
gulp.task('styles-watch', ['styles'], function () {
gulp.watch(`${config.src.styles.app}*.scss`, [ 'styles' ])
})
gulp.task('scripts/lib', function () {
return buildLibScripts(false)
})
gulp.task('scripts/lib-watch', function () {
return buildLibScripts(true)
})
function buildLibScripts (watch) {
var b = browserify({
basedir: __dirname,
debug: true,
cache: {},
packageCache: {},
fullPaths: watch
})
for (var lib in config.externalLibs) {
b.require(lib, { 'expose': lib })
}
return buildScripts(b, 'vendor', watch)
}
gulp.task('scripts', function () {
return buildAppScripts(false)
})
gulp.task('scripts-watch', function () {
return buildAppScripts(true)
})
function buildAppScripts (watch) {
var b = browserify({
basedir: __dirname,
debug: true,
entries: [`${config.src.scripts.app}app.ts`],
cache: {},
packageCache: {},
standalone: 'App',
fullPaths: watch
})
for (var lib in config.externalLibs) {
b.external(lib)
}
return buildScripts(b.plugin(tsify), 'app', watch)
}
function buildScripts (bundle, name, watch) {
if (watch) {
bundle = watchify(bundle)
}
function process () {
bundle
.transform('babelify', { 'presets': [ 'es2015' ] })
.bundle()
.on('error', onError)
.on('log', gutil.log)
.pipe(source(`${name}.js`))
.pipe(buffer())
.pipe(sourcemaps.init({ 'loadMaps': true }))
.pipe(uglify())
.pipe(rename({ 'suffix': '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${config.output.scripts}`))
}
bundle.on('update', process)
return process()
}
gulp.task('html', function () {
return gulp
.src(`${config.src.html}index.html`)
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest(`${config.output.html}`))
})
gulp.task('html-watch', ['html'], function () {
gulp.watch(`${config.src.html}*.html`, [ 'html' ])
})
gulp.task('default', ['styles/lib', 'styles', 'scripts/lib', 'scripts', 'html'])
gulp.task('watch', ['styles/lib-watch', 'styles-watch', 'scripts/lib-watch', 'scripts-watch', 'html-watch'])