import less from 'gulp-less' ; import LessAutoprefix from 'less-plugin-autoprefix' ; import NpmImportPlugin from 'less-plugin-npm-import' ; import { BUILD_ENV_DIST_FILENAME_CSS , DIR_NAME_ASSET , DIR_NAME_CJS , DIR_NAME_COMPONENT_LIBRARY , DIR_NAME_ESM , DIR_NAME_SOURCE , DIR_NAME_UMD , FILENAME_DIST_CSS , FILENAME_DIST_LESS , } from '../constant' ; import getConfigProcessor from '../scripts/utils/getConfigProcessor' ; import compatiblePropertyNameChange from '../scripts/utils/compatiblePropertyNameChange' ; const npmImport = new NpmImportPlugin ( { prefix : '~' } ) ; const autoprefix = new LessAutoprefix ( ) ; const FILE_ASSET_EXT = [ 'png' , 'jpg' , 'jpeg' , 'gif' , 'svg' , 'ttf' , 'eot' , 'woff' , 'woff2' ] ; const FILE_WATCHED_EXT = FILE_ASSET_EXT . concat ( [ 'less' , 'css' ] ) ; export interface StyleConfig { zh css : { zh default entry : string [ ] ; zh default watch : string [ ] ; zh e watchBase : Record < string , string > ; zh output : { zh default es : string ; zh default cjs : string ; zh dist : { zh default path : string ; zh default cssFileName : string ; zh default rawFileName : string ; } ; } ; zh default compiler : any ; zh compilerOptions : Record < string , any > ; } ; zh asset : { zh default entry : string [ ] ; zh default output : string ; } ; zh jsEntry : { zh default entry : string [ ] ; zh e import default autoInjectArcoDep : boolean ; zh default styleSheetExtension : string ; zh default rawEntryFileName : string ; zh default cssEntryFileName : string ; } ; } let config = { css : { entry : [ `${ DIR_NAME_SOURCE }/**/index.less` , `${ DIR_NAME_COMPONENT_LIBRARY }/**/index.less` ] , watch : [ `${ DIR_NAME_SOURCE }/**/*.{${ FILE_WATCHED_EXT . join ( ',' ) }}` , `${ DIR_NAME_COMPONENT_LIBRARY }/**/*.{${ FILE_WATCHED_EXT . join ( ',' ) }}` , ] , watchBase : { } , output : { es : DIR_NAME_ESM , cjs : DIR_NAME_CJS , dist : { path : `${ DIR_NAME_UMD }/css` , cssFileName : FILENAME_DIST_CSS , rawFileName : FILENAME_DIST_LESS , } , } , compiler : less , compilerOptions : { paths : [ 'node_modules' ] , plugins : [ npmImport , autoprefix ] , relativeUrls : true , javascriptEnabled : true , } , } , asset : { entry : [ `${ DIR_NAME_SOURCE }/**/*.{${ FILE_ASSET_EXT . join ( ',' ) }}` , `${ DIR_NAME_COMPONENT_LIBRARY }/**/*.{${ FILE_ASSET_EXT . join ( ',' ) }}` , ] , output : `${ DIR_NAME_UMD }/${ DIR_NAME_ASSET }` , } , jsEntry : { entry : [ `${ DIR_NAME_SOURCE }/style/index.ts` , `${ DIR_NAME_COMPONENT_LIBRARY }/*/style/index.ts` ] , autoInjectArcoDep : true , styleSheetExtension : 'less' , rawEntryFileName : '' , cssEntryFileName : '' , } , } ; config = compatiblePropertyNameChange ( config , [ { now : 'css' , prev : 'less' } ] ) ; const processor = getConfigProcessor ( 'style' ) ; if ( processor ) { config = processor ( config ) || config ; } if ( BUILD_ENV_DIST_FILENAME_CSS ) { config . css . output . dist . cssFileName = BUILD_ENV_DIST_FILENAME_CSS ; } export default config ;