1
- import gulp from ' gulp'
2
- import clean from ' gulp-clean'
3
- import tsc from ' gulp-typescript'
4
- import path from ' path'
5
- import swc from ' gulp-swc'
6
- import esbuild from ' gulp-esbuild'
7
- import watch from ' gulp-watch'
1
+ import gulp from " gulp" ;
2
+ import clean from " gulp-clean" ;
3
+ import tsc from " gulp-typescript" ;
4
+ import path from " path" ;
5
+ import swc from " gulp-swc" ;
6
+ import esbuild from " gulp-esbuild" ;
7
+ import watch from " gulp-watch" ;
8
8
9
- import config from ' ./config'
9
+ import config from " ./config" ;
10
10
11
11
const {
12
12
srcPath,
@@ -17,75 +17,79 @@ const {
17
17
typesPath,
18
18
tsConfigPath,
19
19
swcBuildPath,
20
- entry
20
+ entry,
21
21
} = config ;
22
22
23
+ const genTsc = ( ) => {
24
+ return tsc . createProject ( tsConfigPath ) ;
25
+ } ;
23
26
24
- const gen_tsc = ( ) => {
25
- return tsc . createProject ( tsConfigPath )
26
- }
27
+ gulp . task ( "clean-dev-bundle" , ( ) => {
28
+ return gulp . src ( bundleInDemoPath , { allowEmpty : true } ) . pipe ( clean ( ) ) ;
29
+ } ) ;
27
30
31
+ gulp . task ( "clean-demo-dev-bundle" , ( ) => {
32
+ return gulp . src ( bundleInDemoPath , { allowEmpty : true } ) . pipe ( clean ( ) ) ;
33
+ } ) ;
28
34
29
- gulp . task ( 'clean-dev-bundle' , ( ) => {
30
- return gulp . src ( bundleInDemoPath , { allowEmpty : true } )
31
- . pipe ( clean ( ) )
32
- } )
35
+ gulp . task ( "clean-bundle" , ( ) => {
36
+ return gulp . src ( bundlePath , { allowEmpty : true } ) . pipe ( clean ( ) ) ;
37
+ } ) ;
33
38
34
- gulp . task ( 'clean-demo-dev-bundle' , ( ) => {
35
- return gulp . src ( bundleInDemoPath , { allowEmpty : true } )
36
- . pipe ( clean ( ) )
37
- } )
39
+ gulp . task ( "clean-dts" , ( ) => {
40
+ return gulp . src ( typesPath , { allowEmpty : true } ) . pipe ( clean ( ) ) ;
41
+ } ) ;
38
42
39
- gulp . task ( 'clean-bundle' , ( ) => {
40
- return gulp . src ( bundlePath , { allowEmpty : true } )
41
- . pipe ( clean ( ) )
42
- } )
43
+ gulp . task ( "gen-dts" , ( ) => {
44
+ const tsc = genTsc ( ) ;
45
+ return tsc . src ( ) . pipe ( tsc ( ) ) . pipe ( gulp . dest ( typesPath ) ) ;
46
+ } ) ;
43
47
44
- gulp . task ( 'clean-dts' , ( ) => {
45
- return gulp . src ( typesPath , { allowEmpty : true } )
46
- . pipe ( clean ( ) )
47
- } )
48
-
49
- gulp . task ( 'gen-dts' , ( ) => {
50
- const tsc = gen_tsc ( ) ;
51
- return tsc . src ( ) . pipe ( tsc ( ) )
52
- . pipe ( gulp . dest ( typesPath ) )
53
- } )
54
-
55
- gulp . task ( 'swc-ts-2-js' , ( ) => {
48
+ gulp . task ( "swc-ts-2-js" , ( ) => {
56
49
return gulp
57
50
. src ( path . resolve ( srcPath , "*.ts" ) )
58
51
. pipe ( swc ( swcOptions ) )
59
52
. pipe ( gulp . dest ( swcBuildPath ) ) ;
60
- } )
53
+ } ) ;
61
54
62
- gulp . task ( ' esbuild-bundle' , ( ) => {
55
+ gulp . task ( " esbuild-bundle" , ( ) => {
63
56
return gulp
64
57
. src ( path . resolve ( swcBuildPath , `${ entry } .js` ) )
65
58
. pipe ( esbuild ( esbuildOptions ) )
66
59
. pipe ( gulp . dest ( bundlePath ) ) ;
67
- } )
68
-
69
- gulp . task ( 'copy-2-demo' , ( ) => {
70
- return gulp . src ( path . resolve ( swcBuildPath , "*.js" ) )
71
- . pipe ( gulp . dest ( bundleInDemoPath ) )
72
- } )
60
+ } ) ;
73
61
74
- gulp . task ( 'watch' , ( ) => {
75
- const ts_file = path . resolve ( srcPath , "*.ts" ) ;
76
- const watcher = watch ( ts_file , gulp . series ( 'dev' ) )
77
- watcher . on ( 'change' , function ( path , stats ) {
62
+ gulp . task ( "copy-2-demo" , ( ) => {
63
+ return gulp
64
+ . src ( path . resolve ( swcBuildPath , "*.js" ) )
65
+ . pipe ( gulp . dest ( bundleInDemoPath ) ) ;
66
+ } ) ;
67
+
68
+ gulp . task ( "watch" , ( ) => {
69
+ const tsFile = path . resolve ( srcPath , "*.ts" ) ;
70
+ const watcher = watch ( tsFile , gulp . series ( "dev" ) ) ;
71
+ watcher . on ( "change" , function ( path , stats ) {
78
72
console . log ( `File ${ path } was changed` ) ;
79
73
} ) ;
80
- } )
74
+ } ) ;
81
75
82
76
// build for develop
83
- gulp . task ( 'dev' , gulp . series ( 'clean-dev-bundle' , 'clean-demo-dev-bundle' , 'swc-ts-2-js' , 'copy-2-demo' ) )
77
+ gulp . task (
78
+ "dev" ,
79
+ gulp . series (
80
+ "clean-dev-bundle" ,
81
+ "clean-demo-dev-bundle" ,
82
+ "swc-ts-2-js" ,
83
+ "copy-2-demo"
84
+ )
85
+ ) ;
84
86
85
87
// build for develop & watch
86
- gulp . task ( ' dev-watch' , gulp . series ( ' dev' , ' watch' ) )
87
- // generate .d.ts
88
- gulp . task ( ' dts' , gulp . series ( ' clean-dts' , ' gen-dts' ) )
88
+ gulp . task ( " dev-watch" , gulp . series ( " dev" , " watch" ) ) ;
89
+ // generate .d.ts
90
+ gulp . task ( " dts" , gulp . series ( " clean-dts" , " gen-dts" ) ) ;
89
91
// build for publish
90
- gulp . task ( 'default' , gulp . series ( 'clean-bundle' , 'swc-ts-2-js' , 'esbuild-bundle' , 'dts' ) )
91
-
92
+ gulp . task (
93
+ "default" ,
94
+ gulp . series ( "clean-bundle" , "swc-ts-2-js" , "esbuild-bundle" , "dts" )
95
+ ) ;
0 commit comments