@@ -8,6 +8,7 @@ import * as gulpStripCssComments from 'gulp-strip-css-comments';
88import * as gulpConcatCss from 'gulp-concat-css' ;
99import * as gulpIf from 'gulp-if' ;
1010import * as gulpSourcemaps from 'gulp-sourcemaps' ;
11+ import * as mergeStream from 'merge-stream' ;
1112import * as path from 'path' ;
1213import { pri , srcPath } from '../node' ;
1314import { plugin } from './plugins' ;
@@ -56,43 +57,41 @@ function getStyleFilePath(suffix: string, wholeProject: boolean, sourcePath: str
5657 : path . join ( sourcePath || pri . sourceRoot , srcPath . dir , `**/*.${ suffix } ` ) ;
5758}
5859
59- const buildSass = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
60+ const buildSass = ( wholeProject : boolean , sourcePath : string ) => {
6061 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+ ) ;
7467} ;
7568
76- const buildLess = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string ) => {
69+ const buildLess = ( wholeProject : boolean , sourcePath : string ) => {
7770 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 ) )
8582 . pipe ( gulpIf ( pri . sourceConfig . cssExtract , gulpConcatCss ( pri . sourceConfig . outCssFileName ) ) )
8683 . pipe ( gulpStripCssComments ( ) )
8784 . on ( 'error' , reject )
8885 . pipe ( gulp . dest ( outdir ) )
8986 . 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 ) ;
9695} ;
9796
9897const buildCssWithWebpack = ( outDir : string , copyDir : string ) => {
@@ -198,8 +197,8 @@ export const tsPlusBabel = async (watch = false, wholeProject = false, packageIn
198197 }
199198
200199 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 ) ,
203202
204203 buildTs (
205204 watch ,
0 commit comments