@@ -44,6 +44,9 @@ export default class StyleXPlugin {
4444
4545 transformCss : CSSTransformer ;
4646
47+ include : ( string | RegExp ) [ ] ;
48+ exclude : ( string | RegExp ) [ ] ;
49+
4750 constructor ( {
4851 stylexImports = [ 'stylex' , '@stylexjs/stylex' ] ,
4952 useCSSLayers = false ,
@@ -52,6 +55,8 @@ export default class StyleXPlugin {
5255 transformCss = identityTransfrom ,
5356 transformer = 'rs-compiler' ,
5457 extractCSS = true ,
58+ include = [ ] ,
59+ exclude = [ ] ,
5560 } : StyleXPluginOption = { } ) {
5661 this . useCSSLayers = useCSSLayers ;
5762 this . loaderOption = {
@@ -69,6 +74,35 @@ export default class StyleXPlugin {
6974 extractCSS,
7075 } ;
7176 this . transformCss = transformCss ;
77+ this . include = include ;
78+ this . exclude = exclude ;
79+ }
80+
81+ private shouldProcessModule ( resourcePath : string ) : boolean {
82+ // First check exclude patterns
83+ for ( const pattern of this . exclude ) {
84+ if ( this . matchesPattern ( resourcePath , pattern ) ) {
85+ // If excluded, check if it's explicitly included
86+ for ( const includePattern of this . include ) {
87+ if ( this . matchesPattern ( resourcePath , includePattern ) ) {
88+ return true ; // Explicitly included, override exclude
89+ }
90+ }
91+
92+ return false ; // Excluded and not explicitly included
93+ }
94+ }
95+
96+ // Not excluded, so include it
97+ return true ;
98+ }
99+
100+ private matchesPattern ( resourcePath : string , pattern : string | RegExp ) : boolean {
101+ if ( pattern instanceof RegExp ) {
102+ return pattern . test ( resourcePath ) ;
103+ }
104+
105+ return resourcePath . includes ( pattern ) ;
72106 }
73107
74108 apply ( compiler : webpack . Compiler ) {
@@ -114,8 +148,9 @@ export default class StyleXPlugin {
114148 PLUGIN_NAME ,
115149 ( loaderContext , mod ) => {
116150 const extname = path . extname ( mod . matchResource || mod . resource ) ;
151+ const resourcePath = mod . matchResource || mod . resource ;
117152
118- if ( INCLUDE_REGEXP . test ( extname ) ) {
153+ if ( INCLUDE_REGEXP . test ( extname ) && this . shouldProcessModule ( resourcePath ) ) {
119154 ( loaderContext as SupplementedLoaderContext ) . StyleXWebpackContextKey = {
120155 registerStyleXRules : ( resourcePath , stylexRules ) => {
121156 this . stylexRules . set ( resourcePath , stylexRules ) ;
@@ -134,7 +169,7 @@ export default class StyleXPlugin {
134169 } ) ;
135170 }
136171
137- if ( VIRTUAL_CSS_PATTERN . test ( mod . matchResource || mod . resource ) ) {
172+ if ( VIRTUAL_CSS_PATTERN . test ( resourcePath ) ) {
138173 mod . loaders . push ( {
139174 loader : stylexVirtualLoaderPath ,
140175 options : { } ,
0 commit comments