@@ -30,7 +30,7 @@ function transformConstructableStylesheetsPlugin() {
3030 id . endsWith ( ".css" ) &&
3131 ! id . endsWith ( ".module.css" )
3232 ) {
33- // add .type so Constructable Stylesheets are not precessed by Vite's default pipeline
33+ // add .type so Constructable Stylesheets are not precessed by Vite's default pipeline
3434 return path . join ( path . dirname ( importer ) , `${ id } .type` ) ;
3535 }
3636 } ,
@@ -39,7 +39,7 @@ function transformConstructableStylesheetsPlugin() {
3939 const filename = id . slice ( 0 , - 5 ) ;
4040 const contents = await fs . readFile ( filename , "utf-8" ) ;
4141 const url = new URL ( `file://${ id . replace ( ".type" , "" ) } ` ) ;
42- // "coerce" native conststructable stylesheets into inline JS so Vite / Rollup do not complain
42+ // "coerce" native constructable stylesheets into inline JS so Vite / Rollup do not complain
4343 const request = new Request ( url , {
4444 headers : {
4545 Accept : "text/javascript" ,
@@ -55,14 +55,26 @@ function transformConstructableStylesheetsPlugin() {
5555}
5656
5757function transformRawImports ( ) {
58+ const hint = "?type=raw" ;
59+
5860 return {
5961 name : "transform-raw-imports" ,
6062 enforce : "pre" ,
63+ resolveId : ( id , importer ) => {
64+ if ( id . endsWith ( hint ) ) {
65+ // append .type so .css file paths so they are not precessed by Vite's default CSS pipeline
66+ return path . join ( path . dirname ( importer ) , `${ id . slice ( 0 , id . indexOf ( hint ) ) } .type${ hint } ` ) ;
67+ }
68+ } ,
6169 load : async ( id ) => {
62- if ( id . endsWith ( "?type=raw" ) ) {
63- const filename = id . slice ( 0 , - 9 ) ;
70+ if ( id . endsWith ( hint ) ) {
71+ const filename = id . slice ( 0 , id . indexOf ( `.type ${ hint } ` ) ) ;
6472 const contents = await fs . readFile ( filename , "utf-8" ) ;
65- const response = await rawResource . intercept ( null , null , new Response ( contents ) ) ;
73+ const response = await rawResource . intercept (
74+ new URL ( `file://${ filename } ` ) ,
75+ null ,
76+ new Response ( contents ) ,
77+ ) ;
6678 const body = await response . text ( ) ;
6779
6880 return body ;
0 commit comments