Skip to content

Commit

Permalink
fix: Support TypeScript module imports (#7)
Browse files Browse the repository at this point in the history
* fix: Support TypeScript module imports

Adds support for importing TypeScript modules (`.ts` and `.tsx` files) in the manifest, enabling their inclusion in the build process.

* Fix: Prepend resource paths with `/`

Ensures that resource URLs are treated as root-relative paths. This resolves an issue where resources were being fetched from incorrect locations, especially when the application was deployed on a non-root path.
  • Loading branch information
zgunz42 authored Nov 24, 2024
1 parent 1ddc304 commit 9521ce9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a> Manifest {

if key.ends_with(".css") {
resources.push(Resource::Stylesheet(&chunk.file));
} else if key.ends_with(".js") || key.ends_with(".jsx") {
} else if key.ends_with(".js") || key.ends_with(".jsx") || key.ends_with(".ts") || key.ends_with(".tsx") {
resources.push(Resource::Module(&chunk.file));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ impl<'a> Resource<'a> {
/// the resource.
pub fn to_html(&'a self) -> String {
match *self {
Self::Stylesheet(uri) => format!(r#"<link rel="stylesheet" href="{uri}" />"#),
Self::Module(uri) => format!(r#"<script type="module" src="{uri}"></script>"#),
Self::Stylesheet(uri) => format!(r#"<link rel="stylesheet" href="/{uri}" />"#),
Self::Module(uri) => format!(r#"<script type="module" src="/{uri}"></script>"#),
Self::PreloadModule(uri) => {
format!(r#"<link rel="modulepreload" href="{uri}" />"#)
format!(r#"<link rel="modulepreload" href="/{uri}" />"#)
}
}
}
Expand Down

0 comments on commit 9521ce9

Please sign in to comment.