@@ -43,28 +43,37 @@ const importTransform = (): PluginItem => {
4343 } ;
4444} ;
4545
46+ const fileEndingRegex = / ( t s | j s ) x ( \? .* ) ? $ / ;
47+
4648const lazy = ( ) : PluginOption => {
4749 const cwd = process . cwd ( ) . replaceAll ( osSep , sep ) ;
4850 return {
4951 name : "solid-lazy-css" ,
5052 enforce : "pre" ,
5153 async transform ( src , id ) {
52- // TODO: Try to exclude files by dynamicImport info in moduleGraph
53-
54- if ( ! id . match ( / ( t s | j s ) x ( \? .* ) ? $ / ) ) return ;
54+ if ( ! id . match ( fileEndingRegex ) ) return ;
5555
5656 // The transformed files either import "lazy" or css files
5757 // Therefore we skip, if the src doesn't have any import
5858 if ( src . indexOf ( "import" ) === - 1 ) return ;
5959
60- const hasLazy = src . indexOf ( "lazy" ) !== - 1 ;
61- const localId = relative ( cwd , id ) ;
60+ const plugins : PluginItem [ ] = [ ] ;
61+
62+ const hasDefaultExport = src . indexOf ( "export default" ) !== - 1 ;
63+ if ( hasDefaultExport ) {
64+ const localId = relative ( cwd , id ) ;
65+ plugins . push ( idTransform ( localId ) ) ;
66+ }
67+
68+ const hasLazy = src . indexOf ( "lazy(" ) !== - 1 ;
69+ if ( hasLazy ) plugins . push ( importTransform ( ) ) ;
70+
71+ if ( ! plugins . length ) {
72+ return ;
73+ }
6274
6375 const transformed = await babel . transformAsync ( src , {
64- plugins :
65- hasLazy
66- ? [ idTransform ( localId ) , importTransform ( ) ]
67- : [ idTransform ( localId ) ] ,
76+ plugins,
6877 parserOpts : {
6978 plugins : [ "jsx" , "typescript" ]
7079 } ,
0 commit comments