-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgulpfile.js
103 lines (86 loc) · 3.14 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
var gulp = require('gulp')
var ts = require('gulp-typescript')
var sass = require('gulp-sass')
var concat = require('gulp-concat')
var gutil = require('gulp-util')
var plumber = require('gulp-plumber')
var debug = require('gulp-debug')
var merge = require('merge2')
var del = require('del')
var webpack = require('webpack-stream')
var uglifyjs = require('gulp-uglifyes')
var uglifycss = require('gulp-uglifycss')
var rename = require('gulp-rename')
// commonjs lib (hypertree)
var projectname = 'd3-hypertree'
libname = 'hyt'
watchdep = {}
cssimport = {}
var paths = {
src: './src/',
dist: './dist/'
}
var files = {
darkcss: projectname+`-dark.css`,
lightcss: projectname+`-light.css`,
mainjs: projectname+`.js`
}
var minfiles = {
darkcss: projectname+`-dark.min.css`,
lightcss: projectname+`-light.min.css`,
mainjs: projectname+`.min.js`,
}
// ---------------------------------------------------------------------------------------------
gulp.task('clean', ()=> del(['dist/**/*']))
gulp.task('default', ['watch'])
gulp.task('watch', ['build'], () => {
gulp.watch('../ducd/dist/ducd.js', ['build'])
gulp.watch(paths.src + '**/*.ts', ['build'])
gulp.watch(paths.src + '**/*.scss', ['sass'])
})
// ---------------------------------------------------------------------------------------------
gulp.task('build', ['webpack', 'sass'])
gulp.task('tsc', ()=> {
var tsResult = gulp.src(paths.src + '**/*.ts')
.pipe(plumber())
.pipe(ts.createProject(require('./tsconfig').compilerOptions)())
return merge([
tsResult.dts.pipe(gulp.dest(paths.dist + 'd/')),
tsResult.js.pipe(gulp.dest(paths.dist + 'js/'))
])
})
gulp.task('webpack', ['tsc'], ()=>
gulp.src(paths.dist + 'js/' + files.mainjs)
.pipe(plumber())
.pipe(webpack({
output: {
filename: files.mainjs,
library: libname // use hypertree... in browser
},
devtool: 'source-map',
}))
.pipe(gulp.dest(paths.dist))
)
var scss = (t)=> gulp.src(paths.src + `**/*${t}.scss`) // all *light.scss or *dark.scss
.pipe(plumber())
.pipe(sass())
.pipe(concat(files[t+'css'])) // files.lightcss or files.darkcss
.pipe(gulp.dest(paths.dist))
gulp.task('sass', ()=> merge([scss('light'), scss('dark')]))
// ---------------------------------------------------------------------------------------------
gulp.task('minifyjs', ()=>
gulp.src(paths.dist + files.mainjs)
.pipe(uglifyjs())
.pipe(rename(minfiles.mainjs))
.pipe(gulp.dest(paths.dist)))
gulp.task('minifydarkcss', ()=>
gulp.src(paths.dist + files.darkcss)
.pipe(uglifycss())
.pipe(rename(minfiles.darkcss))
.pipe(gulp.dest(paths.dist)))
gulp.task('minifylightcss', ()=>
gulp.src(paths.dist + files.lightcss)
.pipe(uglifycss())
.pipe(rename(minfiles.lightcss))
.pipe(gulp.dest(paths.dist)))
gulp.task('minify', ['minifyjs', 'minifydarkcss', 'minifylightcss'])