-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
59 lines (49 loc) · 1.57 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
const browserify = require('browserify');
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const rename = require('gulp-rename');
const ts = require('gulp-typescript');
const runSequence = require('run-sequence');
const del = require('del');
const p = require('./package.json');
const config = {
src: "./src",
pkgname: p.name,
filename: p.name + ".js",
dst: "./dist"
};
const tsProject = ts.createProject('tsconfig.json');
function getBrowserify(tinyify) {
const b = browserify({
entries: config.src + '/index.ts',
standalone: config.pkgname
}).plugin('tsify');
return tinyify === true ? b.plugin('tinyify').bundle() : b.bundle();
}
// Clean the output folder
gulp.task('clean', () => del([config.dst]));
// Bundle the project for the browser
gulp.task('browserify', () => {
return getBrowserify()
.pipe(source(config.filename))
.pipe(gulp.dest(config.dst + '/browser'));
});
// Bundle the project and tinify (flatPack, treeShake) it for the browser
gulp.task('tinyify', () => {
return getBrowserify(true)
.pipe(source(config.filename))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(config.dst + '/browser'));
});
// Compile the project for Node and Typescript
gulp.task('tsc', () => {
return gulp.src([config.src + '/**/*.ts'])
.pipe(tsProject())
.pipe(gulp.dest(config.dst + '/node'));
});
// Build step: build JS, tiny JS and TS declaration in parallel
gulp.task('build', (cb) => {
return runSequence('clean', ['browserify', 'tinyify', 'tsc'], cb);
});
// default task
gulp.task('default', ['browserify']);