11import * as gulp from 'gulp' ;
2+ import * as fs from 'fs-extra' ;
23import * as gulpBabel from 'gulp-babel' ;
34import * as gulpSass from 'gulp-sass' ;
45import * as gulpWatch from 'gulp-watch' ;
@@ -13,6 +14,7 @@ import { getBabelOptions } from './babel-options';
1314import { globalState } from './global-state' ;
1415import { babelPluginTransformImport } from './babel-plugin-transfer-import' ;
1516import { PackageInfo } from './define' ;
17+ import { runWebpack } from './webpack' ;
1618
1719function getGulpByWatch ( watch : boolean , filesPath : string ) {
1820 if ( watch ) {
@@ -66,6 +68,27 @@ const buildSass = (watch: boolean, outdir: string, wholeProject: boolean, source
6668 } ) ;
6769} ;
6870
71+ const buildCssWithWebpack = ( outDir : string , copyDir : string ) => {
72+ const cssFileNames = Object . keys ( pri . sourceConfig . componentEntries ) . map ( file => `${ file } .css` ) ;
73+
74+ return runWebpack ( {
75+ mode : 'production' ,
76+ entryPath : pri . sourceConfig . componentEntries ,
77+ distDir : outDir ,
78+ outFileName : '[name].js' ,
79+ outCssFileName : '[name].css' ,
80+ } ) . then ( ( ) => {
81+ const distFiles = fs . readdirSync ( outDir ) ;
82+ distFiles . forEach ( file => {
83+ const basename = path . basename ( file ) ;
84+ if ( ! cssFileNames . includes ( basename ) ) {
85+ fs . removeSync ( path . join ( outDir , file ) ) ;
86+ }
87+ } ) ;
88+ fs . copySync ( outDir , copyDir ) ;
89+ } ) ;
90+ } ;
91+
6992const mvResources = ( watch : boolean , outdir : string , wholeProject : boolean , sourcePath : string , sourceType : string ) => {
7093 const selectedSourceType = sourceType || pri . selectedSourceType ;
7194 const targetPath =
@@ -126,9 +149,14 @@ export const tsPlusBabel = async (watch = false, wholeProject = false, packageIn
126149 const sourcePath = packageInfo ? packageInfo . rootPath : null ;
127150 const sourceType = packageInfo ? packageInfo . name : null ;
128151
152+ // build component with webpack if config multy entries
153+ if ( pri . sourceConfig . componentEntries ) {
154+ await buildCssWithWebpack ( mainDistPath , moduleDistPath ) ;
155+ }
156+
129157 return Promise . all ( [
130- buildSass ( watch , mainDistPath , wholeProject , sourcePath ) ,
131- buildSass ( watch , moduleDistPath , wholeProject , sourcePath ) ,
158+ pri . sourceConfig . componentEntries ? null : buildSass ( watch , mainDistPath , wholeProject , sourcePath ) ,
159+ pri . sourceConfig . componentEntries ? null : buildSass ( watch , moduleDistPath , wholeProject , sourcePath ) ,
132160
133161 buildTs (
134162 watch ,
0 commit comments