-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
46 lines (44 loc) · 1.46 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
'use strict';
const gulp = require("gulp");
const minify = require('gulp-minify');
const inject = require("gulp-inject-string");
const ts = require('gulp-typescript');
const plus = require('typescript-plus');
const merge = require('merge2');
const del = require('del');
const tsProject = ts.createProject('tsconfig.json', { typescript: plus });
const outFile = tsProject.config.compilerOptions.outFile;
const outNames = outFile.split('/');
const lib_name = outNames[outNames.length - 1].replace('.js', '');
const module_name = 'library';
gulp.task('clean', () => {
return del([
'bin',
'dist'
]);
});
gulp.task('buildJs', () => {
return tsProject.src()
.pipe(tsProject())
.js
.pipe(inject.replace('var ' + module_name + ';', ''))
.pipe(inject.prepend('var ' + module_name + ';\n'))
.pipe(inject.prepend('window.' + module_name + ' = {};\n'))
.pipe(inject.replace('var __extends =', 'window.__extends ='))
.pipe(minify({ ext: { min: ".min.js" } }))
.pipe(gulp.dest('./bin'));
});
gulp.task("buildDts", ["buildJs"], () => {
return tsProject.src()
.pipe(tsProject())
.dts
.pipe(gulp.dest('./bin'));
});
gulp.task("build", ["buildDts"], () => {
return merge([
gulp.src('bin/**/*')
.pipe(gulp.dest('./dist/' + lib_name + '/')),
// gulp.src('bin/*.ts').pipe(),//复制dts到其他依赖项目中
]);
});
gulp.task('default', ['clean', 'build']);