1+ import { type Plugin } from 'esbuild' ;
12import { type Options } from 'tsup' ;
23import lightningCssPlugin from 'unplugin-lightningcss/esbuild' ;
34
@@ -9,8 +10,8 @@ const env = process.env.NODE_ENV || 'development';
910const { npm_package_version } = process . env ;
1011const istanbulPredicate : Predicate = args => defaultPredicate ( args ) && ! / \. w o r k e r \. [ c m ] ? [ j t ] s $ / u. test ( args . path ) ;
1112
12- type Plugin = NonNullable < Options [ 'plugins' ] > [ number ] ;
13- const disablePlugin = ( pluginName : string ) : Plugin => ( {
13+ type EsbuildPlugin = NonNullable < Options [ 'plugins' ] > [ number ] ;
14+ const disablePlugin = ( pluginName : string ) : EsbuildPlugin => ( {
1415 name : `disable-plugin-${ pluginName } ` ,
1516 esbuildOptions : options => {
1617 const plugin = options . plugins ?. find ( ( { name } ) => name === pluginName ) ;
@@ -20,34 +21,47 @@ const disablePlugin = (pluginName: string): Plugin => ({
2021 }
2122} ) ;
2223
23- const cssPlugin = lightningCssPlugin ( {
24- include : [ / \. m o d u l e \. c s s $ / u] ,
25- options : {
26- cssModules : {
27- pattern : 'w[hash]_[local]' ,
28- pure : true ,
29- animation : false ,
30- grid : false ,
31- customIdents : false
32- }
24+ // Due to a bug in unplugin, we cannot use the Lightning CSS unplugin directly.
25+ // https://github.com/unjs/unplugin/issues/546
26+ // To workaround the bug, we are converting it back to esbuild plugin so we can apply a custom `filter`.
27+ // Otherwise, unplugin will apply `filter: /.*/` and trigger the bug down the road.
28+ const cssPlugin : Plugin = {
29+ name : 'lightningcss' ,
30+ setup : build => {
31+ lightningCssPlugin ( {
32+ include : [ / \. m o d u l e \. c s s $ / u] ,
33+ options : {
34+ cssModules : {
35+ pattern : 'w[hash]_[local]' ,
36+ pure : true ,
37+ animation : false ,
38+ grid : false ,
39+ customIdents : false
40+ }
41+ }
42+ } ) . setup ( {
43+ ...build ,
44+ // eslint-disable-next-line require-unicode-regexp
45+ onLoad : ( _filter , fn ) => build . onLoad ( { filter : / ( \. m o d u l e _ b u i l t \. c s s | \? c s s _ m o d u l e ) $ / } , fn )
46+ } ) ;
3347 }
34- } ) ;
48+ } ;
3549
3650function applyConfig (
3751 overrideOptions : (
3852 options : Omit < Options , 'entry' | 'onSuccess' > & {
3953 define : Record < string , string > ;
40- esbuildPlugins : Plugin [ ] ;
54+ esbuildPlugins : EsbuildPlugin [ ] ;
4155 target : Target [ ] ;
4256 }
4357 ) => Options & {
4458 define : Record < string , string > ;
45- esbuildPlugins : Plugin [ ] ;
59+ esbuildPlugins : EsbuildPlugin [ ] ;
4660 target : Target [ ] ;
4761 }
4862) : Options & {
4963 define : Record < string , string > ;
50- esbuildPlugins : Plugin [ ] ;
64+ esbuildPlugins : EsbuildPlugin [ ] ;
5165 target : Target [ ] ;
5266} {
5367 const nextOptions = overrideOptions ( {
0 commit comments