@@ -56,7 +56,7 @@ export default (options = {}) => {
5656 name : "import-css" ,
5757
5858 resolveId ( source , importer ) {
59- if ( source . endsWith ( ".css" ) ) {
59+ if ( source . endsWith ( ".css" ) && ( source . startsWith ( "." ) || source . startsWith ( "/" ) ) ) {
6060 ( imports [ importer ] = imports [ importer ] ?? [ ] ) . push ( source ) ;
6161 return { id : path . resolve ( path . dirname ( importer ) , source ) } ;
6262 }
@@ -119,7 +119,8 @@ export default (options = {}) => {
119119 for ( let id of stylesheets ) {
120120 const relativeToEntry = path . dirname ( path . relative ( entryChunk , id ) ) ;
121121 const outputPath = opts . dir ? opts . dir : path . dirname ( opts . file ) ;
122- const fileName = path . join ( path . join ( outputPath , relativeToEntry ) , path . basename ( id ) ) ;
122+ const relativePath = path . join ( path . join ( outputPath , relativeToEntry ) , path . basename ( id ) ) ;
123+ const fileName = relativePath . includes ( "node_modules" ) ? relativePath . split ( "/" ) . at ( - 1 ) : relativePath ;
123124
124125 if ( styles [ id ] . trim ( ) . length <= 0 && ! alwaysOutput ) continue ;
125126
@@ -132,7 +133,10 @@ export default (options = {}) => {
132133 if ( chunk . type != "chunk" || ! imports [ chunk . facadeModuleId ] ) continue ;
133134
134135 for ( let file of imports [ chunk . facadeModuleId ] . reverse ( ) ) {
135- chunk . code = `import "${ file } ";\n${ chunk . code } ` ;
136+ const importPath = file . includes ( "node_modules" ) ? `./${ file . split ( "/" ) . at ( - 1 ) } ` : file ;
137+ if ( chunk . code . includes ( importPath ) ) continue ;
138+
139+ chunk . code = `import "${ importPath } ";\n${ chunk . code } ` ;
136140 }
137141 }
138142 }
0 commit comments