-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
63 lines (52 loc) · 1.97 KB
/
Copy pathgulpfile.js
File metadata and controls
63 lines (52 loc) · 1.97 KB
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
/** Usage:
* "gulp debug" for building debug files
* "gulp watch" for building debug files and recreate when changed
* "gulp build" for building release files
*/
'use strict'
const gulp = require('gulp')
const less = require('gulp-less')
const browserify = require('browserify')
const fs = require('fs')
const TABLEMODIFY_ENTRY_SCRIPT = './src/tablemodify.js'
const TARGET_TABLEMODIFY = './dist/tablemodify.js'
const TARGET_TABLEMODIFY_MIN = './dist/tablemodify.min.js'
var debugInstance
gulp.task('default', () => null)
gulp.task('build', ['buildjs', 'less'])
gulp.task('debug', ['less', 'write_debugjs'])
gulp.task('watch', ['debug'], () => {
gulp.watch('./src/**/*.js', ['write_debugjs'])
gulp.watch('./src/**/*.less', ['less'])
// Return never-resolving promise so that the task will never end
return new Promise(() => null)
})
gulp.task('write_debugjs', () => {
if (!debugInstance) {
debugInstance = browserify({
entries: [TABLEMODIFY_ENTRY_SCRIPT],
cache: {},
packageCache: {},
debug: true
}).transform('babelify', {presets: ['es2015']})
}
// Write the debug build to both uncompressed and minified target file
debugInstance.bundle().pipe(fs.createWriteStream(TARGET_TABLEMODIFY))
return debugInstance.bundle().pipe(fs.createWriteStream(TARGET_TABLEMODIFY_MIN))
})
// Task which creates minified and normal js build
gulp.task('buildjs', () => {
getBrowserify().bundle().pipe(fs.createWriteStream(TARGET_TABLEMODIFY))
return getBrowserify().transform('uglifyify', {global: true}).bundle().pipe(fs.createWriteStream(TARGET_TABLEMODIFY_MIN))
})
// Helper task for recompiling less files
gulp.task('less', () => {
return gulp.src('./src/**/*.less')
.pipe(less().on('error', err => console.log(err)))
.pipe(gulp.dest('./dist'))
})
// ######## Helper functions #############
function getBrowserify () {
return browserify(TABLEMODIFY_ENTRY_SCRIPT)
.transform('babelify', {presets: ['es2015']})
}