@@ -9,8 +9,12 @@ import { compile } from "sass";
99const uuid = ( ) => ( Date . now ( ) * Math . random ( ) ) . toString ( 36 ) . slice ( 0 , 8 ) ;
1010
1111interface CSSModulePluginOptions {
12+ /** by default name is generated without hash */
1213 generateScopedName ?: string | ( ( name : string , filename : string , css : string ) => string ) ;
14+ /** set skipAutoPrefixer to true to disable autoprefixer */
1315 skipAutoPrefixer ?: boolean ;
16+ /** global CSS class prefix. @defaultValue "" */
17+ globalPrefix ?: string ;
1418}
1519
1620function applyAutoPrefixer ( build : PluginBuild , options : CSSModulePluginOptions , write ?: boolean ) {
@@ -89,12 +93,14 @@ function handleModules(
8993 } ) ) ;
9094}
9195
92- const cssPlugin : ( options : CSSModulePluginOptions ) => Plugin = ( options = { } ) => ( {
96+ const cssPlugin : ( options ? : CSSModulePluginOptions ) => Plugin = ( options = { } ) => ( {
9397 name : "esbuild-plugin-react18-css-" + uuid ( ) ,
9498 setup ( build ) : void {
9599 const write = build . initialOptions . write ;
96100 if ( ! options . generateScopedName ) {
101+ const globalPrefix = options . globalPrefix ?? "" ;
97102 options . generateScopedName = ( name , filename ) =>
103+ ( globalPrefix ? `${ globalPrefix } __` : "" ) +
98104 `${ path . basename ( filename ) . split ( "." ) [ 0 ] } __${ name } ` ;
99105 }
100106 handleModules ( build , options ) ;
0 commit comments