File tree Expand file tree Collapse file tree 6 files changed +38
-3
lines changed Expand file tree Collapse file tree 6 files changed +38
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @sveltejs/kit ' : patch
3
+ ---
4
+
5
+ fix: make paths in .css assets relative
Original file line number Diff line number Diff line change @@ -1078,10 +1078,30 @@ async function kit({ svelte_config }) {
1078
1078
) ;
1079
1079
1080
1080
const assets_path = `${ kit . appDir } /immutable/assets` ;
1081
+ const server_assets = `${ out } /server/${ assets_path } ` ;
1082
+ const client_assets = `${ out } /client/${ assets_path } ` ;
1081
1083
1082
- copy ( `${ out } /server/${ assets_path } ` , `${ out } /client/${ assets_path } ` , {
1083
- filter : ( basename ) => ! ssr_stylesheets . has ( `${ assets_path } /${ basename } ` )
1084
- } ) ;
1084
+ if ( fs . existsSync ( server_assets ) ) {
1085
+ for ( const file of fs . readdirSync ( server_assets ) ) {
1086
+ const src = `${ server_assets } /${ file } ` ;
1087
+ const dest = `${ client_assets } /${ file } ` ;
1088
+
1089
+ if ( fs . existsSync ( dest ) || ssr_stylesheets . has ( `${ assets_path } /${ file } ` ) ) {
1090
+ continue ;
1091
+ }
1092
+
1093
+ if ( file . endsWith ( '.css' ) ) {
1094
+ // make absolute paths in CSS relative, for portability
1095
+ const content = fs
1096
+ . readFileSync ( src , 'utf-8' )
1097
+ . replaceAll ( `${ kit . paths . base } /${ assets_path } ` , '.' ) ;
1098
+
1099
+ fs . writeFileSync ( src , content ) ;
1100
+ }
1101
+
1102
+ copy ( src , dest ) ;
1103
+ }
1104
+ }
1085
1105
1086
1106
/** @type {import('vite').Manifest } */
1087
1107
const client_manifest = JSON . parse ( read ( `${ out } /client/.vite/manifest.json` ) ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { dev } from '$app/environment';
2
2
import { read } from '$app/server' ;
3
3
import auto from './[auto].txt' ;
4
4
import url from './[url].txt?url' ;
5
+ import styles from './[styles].css?url' ;
5
6
6
7
/** @type {Record<string, { default: string }> } */
7
8
const local_glob = import . meta. glob ( './assets/**' , {
@@ -23,6 +24,7 @@ export async function load() {
23
24
return {
24
25
auto : await read ( auto ) . text ( ) ,
25
26
url : await read ( url ) . text ( ) ,
27
+ styles : await read ( styles ) . text ( ) ,
26
28
local_glob : await read ( local_glob [ './assets/[file].txt' ] . default ) . text ( ) ,
27
29
external_glob : await read ( Object . values ( external_glob ) [ 0 ] . default ) . text ( ) ,
28
30
svg : await read ( local_glob [ './assets/icon.svg' ] . default ) . text ( )
Original file line number Diff line number Diff line change 4
4
5
5
<p data-testid ="auto" >{data .auto }</p >
6
6
<p data-testid ="url" >{data .url }</p >
7
+ <p data-testid ="styles" >{data .styles }</p >
7
8
<p data-testid ="local_glob" >{data .local_glob }</p >
8
9
<p data-testid ="external_glob" >{data .external_glob }</p >
9
10
<div data-testid ="svg" >{@html data .svg }</div >
Original file line number Diff line number Diff line change
1
+ .logo {
2
+ background : url(../ asset-import/large.jpg);
3
+ }
Original file line number Diff line number Diff line change @@ -1072,6 +1072,7 @@ test.describe('$app/server', () => {
1072
1072
1073
1073
const auto = await page . textContent ( '[data-testid="auto"]' ) ;
1074
1074
const url = await page . textContent ( '[data-testid="url"]' ) ;
1075
+ const styles = await page . textContent ( '[data-testid="styles"]' ) ;
1075
1076
const local_glob = await page . textContent ( '[data-testid="local_glob"]' ) ;
1076
1077
const external_glob = await page . textContent ( '[data-testid="external_glob"]' ) ;
1077
1078
const svg = await page . innerHTML ( '[data-testid="svg"]' ) ;
@@ -1084,5 +1085,8 @@ test.describe('$app/server', () => {
1084
1085
'Imported with url glob from the read-file test in basics. Placed here outside the app folder to force a /@fs prefix 😎'
1085
1086
) ;
1086
1087
expect ( svg ) . toContain ( '<rect width="24" height="24" rx="2" fill="#ff3e00"></rect>' ) ;
1088
+
1089
+ // check that paths in .css files are relative
1090
+ expect ( styles ) . toContain ( 'url(.' ) ;
1087
1091
} ) ;
1088
1092
} ) ;
You can’t perform that action at this time.
0 commit comments