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