@@ -2,6 +2,7 @@ import * as gulp from 'gulp';
22import * as fs from 'fs-extra' ;
33import * as gulpBabel from 'gulp-babel' ;
44import * as gulpSass from 'gulp-sass' ;
5+ import * as gulpLess from 'gulp-less' ;
56import * as gulpWatch from 'gulp-watch' ;
67import * as gulpStripCssComments from 'gulp-strip-css-comments' ;
78import * as gulpConcatCss from 'gulp-concat-css' ;
@@ -20,9 +21,17 @@ function getGulpByWatch(watch: boolean, filesPath: string) {
2021 if ( watch ) {
2122 return gulpWatch ( filesPath ) ;
2223 }
24+ /** 文件匹配 */
2325 return gulp . src ( filesPath ) ;
2426}
2527
28+ function getCssByWatch ( watch : boolean , filesPath : Array < any > ) {
29+ if ( watch ) {
30+ return gulpWatch ( filesPath ) ;
31+ }
32+ /** 文件匹配 */
33+ return gulp . src ( filesPath ) ;
34+ }
2635const buildTs = ( watch : boolean , outdir : string , babelOptions : any , wholeProject : boolean , sourcePath : string ) => {
2736 const targetPath = wholeProject
2837 ? path . join ( pri . projectRootPath , '{src,packages}/**/*.{ts,tsx}' )
@@ -47,19 +56,28 @@ const buildTs = (watch: boolean, outdir: string, babelOptions: any, wholeProject
4756 } ) ;
4857} ;
4958
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 ) ;
5669 return new Promise ( ( resolve , reject ) => {
57- getGulpByWatch ( watch , targetPath )
70+ getCssByWatch ( watch , [ targetScssPath , targetLessPath ] )
5871 . pipe (
5972 gulpSass ( {
6073 includePaths : path . join ( pri . projectRootPath , 'node_modules' ) ,
6174 } ) ,
6275 )
76+ . pipe (
77+ gulpLess ( {
78+ paths : [ path . join ( pri . projectRootPath , 'node_modules' , 'includes' ) ] ,
79+ } ) ,
80+ )
6381 . pipe ( gulpIf ( pri . sourceConfig . cssExtract , gulpConcatCss ( pri . sourceConfig . outCssFileName ) ) )
6482 . pipe ( gulpStripCssComments ( ) )
6583 . on ( 'error' , reject )
@@ -171,8 +189,8 @@ export const tsPlusBabel = async (watch = false, wholeProject = false, packageIn
171189 }
172190
173191 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 ) ,
176194
177195 buildTs (
178196 watch ,
0 commit comments