@@ -8,6 +8,7 @@ import * as gulpStripCssComments from 'gulp-strip-css-comments';
8
8
import * as gulpConcatCss from 'gulp-concat-css' ;
9
9
import * as gulpIf from 'gulp-if' ;
10
10
import * as gulpSourcemaps from 'gulp-sourcemaps' ;
11
+ import * as mergeStream from 'merge-stream' ;
11
12
import * as path from 'path' ;
12
13
import { pri , srcPath } from '../node' ;
13
14
import { plugin } from './plugins' ;
@@ -56,43 +57,41 @@ function getStyleFilePath(suffix: string, wholeProject: boolean, sourcePath: str
56
57
: path . join ( sourcePath || pri . sourceRoot , srcPath . dir , `**/*.${ suffix } ` ) ;
57
58
}
58
59
59
- const buildSass = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
60
+ const buildSass = ( wholeProject : boolean , sourcePath : string ) => {
60
61
const targetScssPath = getStyleFilePath ( 'scss' , wholeProject , sourcePath ) ;
61
- return new Promise ( ( resolve , reject ) => {
62
- getGulpByWatch ( watch , targetScssPath )
63
- . pipe (
64
- gulpSass ( {
65
- includePaths : path . join ( pri . projectRootPath , 'node_modules' ) ,
66
- } ) ,
67
- )
68
- . pipe ( gulpIf ( pri . sourceConfig . cssExtract , gulpConcatCss ( pri . sourceConfig . outCssFileName ) ) )
69
- . pipe ( gulpStripCssComments ( ) )
70
- . on ( 'error' , reject )
71
- . pipe ( gulp . dest ( outdir ) )
72
- . on ( 'end' , resolve ) ;
73
- } ) ;
62
+ return gulp . src ( targetScssPath ) . pipe (
63
+ gulpSass ( {
64
+ includePaths : path . join ( pri . projectRootPath , 'node_modules' ) ,
65
+ } ) ,
66
+ ) ;
74
67
} ;
75
68
76
- const buildLess = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
69
+ const buildLess = ( wholeProject : boolean , sourcePath : string ) => {
77
70
const targetLessPath = getStyleFilePath ( 'less' , wholeProject , sourcePath ) ;
78
- return new Promise ( ( resolve , reject ) => {
79
- getGulpByWatch ( watch , targetLessPath )
80
- . pipe (
81
- gulpLess ( {
82
- paths : [ path . join ( pri . projectRootPath , 'node_modules' , 'includes' ) ] ,
83
- } ) ,
84
- )
71
+ return gulp . src ( targetLessPath ) . pipe (
72
+ gulpLess ( {
73
+ paths : [ path . join ( pri . projectRootPath , 'node_modules' , 'includes' ) ] ,
74
+ } ) ,
75
+ ) ;
76
+ } ;
77
+
78
+ const buildSassAndLess = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
79
+ const targetPath = getStyleFilePath ( '{scss,less}' , wholeProject , sourcePath ) ;
80
+ const mergeStyle = ( resolve : ( value ?: any ) => void , reject : ( value ?: any ) => void ) =>
81
+ mergeStream ( buildLess ( wholeProject , sourcePath ) , buildSass ( wholeProject , sourcePath ) )
85
82
. pipe ( gulpIf ( pri . sourceConfig . cssExtract , gulpConcatCss ( pri . sourceConfig . outCssFileName ) ) )
86
83
. pipe ( gulpStripCssComments ( ) )
87
84
. on ( 'error' , reject )
88
85
. pipe ( gulp . dest ( outdir ) )
89
86
. on ( 'end' , resolve ) ;
90
- } ) ;
91
- } ;
92
-
93
- const buildSassOrLess = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
94
- buildSass ( watch , outdir , wholeProject , sourcePath ) ;
95
- buildLess ( watch , outdir , wholeProject , sourcePath ) ;
87
+ if ( watch ) {
88
+ return new Promise ( ( resolve , reject ) => {
89
+ gulpWatch ( targetPath , ( ) => {
90
+ mergeStyle ( resolve , reject ) ;
91
+ } ) ;
92
+ } ) ;
93
+ }
94
+ return new Promise ( mergeStyle ) ;
96
95
} ;
97
96
98
97
const buildCssWithWebpack = ( outDir : string , copyDir : string ) => {
@@ -198,8 +197,8 @@ export const tsPlusBabel = async (watch = false, wholeProject = false, packageIn
198
197
}
199
198
200
199
return Promise . all ( [
201
- pri . sourceConfig . componentEntries ? null : buildSassOrLess ( watch , mainDistPath , wholeProject , sourcePath ) ,
202
- pri . sourceConfig . componentEntries ? null : buildSassOrLess ( watch , moduleDistPath , wholeProject , sourcePath ) ,
200
+ pri . sourceConfig . componentEntries ? null : buildSassAndLess ( watch , mainDistPath , wholeProject , sourcePath ) ,
201
+ pri . sourceConfig . componentEntries ? null : buildSassAndLess ( watch , moduleDistPath , wholeProject , sourcePath ) ,
203
202
204
203
buildTs (
205
204
watch ,
0 commit comments