-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (82 loc) · 1.84 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
/*jshint globalstrict: true*/
/*global require*/
'use strict'
const gulp = require('gulp')
const jdists = require('gulp-jdists')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const examplejs = require('gulp-examplejs')
const typescript = require('gulp-typescript')
const replace = require('gulp-replace')
const merge2 = require('merge2')
const pkg = require('./package')
function build() {
let tsResult = gulp
.src('src/*.ts')
.pipe(jdists())
.pipe(gulp.dest('lib'))
.pipe(
typescript({
target: 'ES5',
declaration: true,
module: 'umd',
})
)
return merge2([
tsResult.dts.pipe(gulp.dest('lib')),
tsResult.js
.pipe(
replace(
/(\(function\s*\()(factory\)\s*\{)/,
'$1root, $2\n /* istanbul ignore next */'
)
)
.pipe(replace(/var __assign = /, '/* istanbul ignore next */\n$&'))
.pipe(
replace(
/(define\(\["require",\s*"exports"\],\s*factory\);\s*\})/,
`$1 else { factory(null, root["${pkg.name}"] = {}); }`
)
)
.pipe(
replace(
/(\s*\}\s*\)\s*\()(function\s*\(require,\s*exports\)\s*\{)/,
'$1this, $2'
)
)
.pipe(gulp.dest('lib')),
])
}
gulp.task(build)
function compress() {
return gulp
.src('lib/index.js')
.pipe(uglify())
.pipe(rename('index.min.js'))
.pipe(gulp.dest('lib'))
}
gulp.task(compress)
function example() {
return gulp
.src(['src/*.ts'])
.pipe(
jdists({
trigger: 'example',
})
)
.pipe(
examplejs({
header: `
const iorder = require('../')
`,
})
)
.pipe(
rename({
extname: '.js',
})
)
.pipe(gulp.dest('test'))
}
gulp.task(example)
gulp.task('dist', gulp.parallel(build, example, compress))