@@ -2,6 +2,7 @@ import * as gulp from 'gulp';
2
2
import * as fs from 'fs-extra' ;
3
3
import * as gulpBabel from 'gulp-babel' ;
4
4
import * as gulpSass from 'gulp-sass' ;
5
+ import * as gulpLess from 'gulp-less' ;
5
6
import * as gulpWatch from 'gulp-watch' ;
6
7
import * as gulpStripCssComments from 'gulp-strip-css-comments' ;
7
8
import * as gulpConcatCss from 'gulp-concat-css' ;
@@ -20,9 +21,17 @@ function getGulpByWatch(watch: boolean, filesPath: string) {
20
21
if ( watch ) {
21
22
return gulpWatch ( filesPath ) ;
22
23
}
24
+ /** 文件匹配 */
23
25
return gulp . src ( filesPath ) ;
24
26
}
25
27
28
+ function getCssByWatch ( watch : boolean , filesPath : Array < any > ) {
29
+ if ( watch ) {
30
+ return gulpWatch ( filesPath ) ;
31
+ }
32
+ /** 文件匹配 */
33
+ return gulp . src ( filesPath ) ;
34
+ }
26
35
const buildTs = ( watch : boolean , outdir : string , babelOptions : any , wholeProject : boolean , sourcePath : string ) => {
27
36
const targetPath = wholeProject
28
37
? path . join ( pri . projectRootPath , '{src,packages}/**/*.{ts,tsx}' )
@@ -47,19 +56,28 @@ const buildTs = (watch: boolean, outdir: string, babelOptions: any, wholeProject
47
56
} ) ;
48
57
} ;
49
58
50
- const buildSass = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
51
- const targetPath =
52
- wholeProject || ( pri . selectedSourceType === 'root' && pri . sourceConfig . cssExtract )
53
- ? path . join ( pri . projectRootPath , '{src,packages}/**/*.scss' )
54
- : path . join ( sourcePath || pri . sourceRoot , srcPath . dir , '**/*.scss' ) ;
55
- const a = 1 ;
59
+ /** 获取样式文件路径 */
60
+ function getStyleFilePath ( suffix : string , wholeProject : boolean , sourcePath : string ) {
61
+ return wholeProject || ( pri . selectedSourceType === 'root' && pri . sourceConfig . cssExtract )
62
+ ? path . join ( pri . projectRootPath , `{src,packages}/**/*.${ suffix } ` )
63
+ : path . join ( sourcePath || pri . sourceRoot , srcPath . dir , `**/*.${ suffix } ` ) ;
64
+ }
65
+
66
+ const buildSassAndLess = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
67
+ const targetScssPath = getStyleFilePath ( 'scss' , wholeProject , sourcePath ) ;
68
+ const targetLessPath = getStyleFilePath ( 'less' , wholeProject , sourcePath ) ;
56
69
return new Promise ( ( resolve , reject ) => {
57
- getGulpByWatch ( watch , targetPath )
70
+ getCssByWatch ( watch , [ targetScssPath , targetLessPath ] )
58
71
. pipe (
59
72
gulpSass ( {
60
73
includePaths : path . join ( pri . projectRootPath , 'node_modules' ) ,
61
74
} ) ,
62
75
)
76
+ . pipe (
77
+ gulpLess ( {
78
+ paths : [ path . join ( pri . projectRootPath , 'node_modules' , 'includes' ) ] ,
79
+ } ) ,
80
+ )
63
81
. pipe ( gulpIf ( pri . sourceConfig . cssExtract , gulpConcatCss ( pri . sourceConfig . outCssFileName ) ) )
64
82
. pipe ( gulpStripCssComments ( ) )
65
83
. on ( 'error' , reject )
@@ -171,8 +189,8 @@ export const tsPlusBabel = async (watch = false, wholeProject = false, packageIn
171
189
}
172
190
173
191
return Promise . all ( [
174
- pri . sourceConfig . componentEntries ? null : buildSass ( watch , mainDistPath , wholeProject , sourcePath ) ,
175
- pri . sourceConfig . componentEntries ? null : buildSass ( watch , moduleDistPath , wholeProject , sourcePath ) ,
192
+ pri . sourceConfig . componentEntries ? null : buildSassAndLess ( watch , mainDistPath , wholeProject , sourcePath ) ,
193
+ pri . sourceConfig . componentEntries ? null : buildSassAndLess ( watch , moduleDistPath , wholeProject , sourcePath ) ,
176
194
177
195
buildTs (
178
196
watch ,
0 commit comments