-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow file URLs to be used as import specifiers (#9407)
* Allow file URLs to be used as import specifiers * Update packages/astro/src/vite-plugin-fileurl/index.ts Co-authored-by: Nate Moore <[email protected]> --------- Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
63b3cd1
commit 546d92c
Showing
6 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Allows file URLs as import specifiers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Plugin as VitePlugin } from 'vite'; | ||
|
||
export default function vitePluginFileURL({}): VitePlugin { | ||
return { | ||
name: 'astro:vite-plugin-file-url', | ||
resolveId(source, importer) { | ||
if(source.startsWith('file://')) { | ||
const rest = source.slice(7); | ||
return this.resolve(rest, importer); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/astro/test/fixtures/astro-basic/src/pages/fileurl.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
import {capitalize} from 'file://../strings.js'; | ||
--- | ||
|
||
<html> | ||
<head><title>Testing</title></head> | ||
<body> | ||
<h1>{capitalize('works')</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export function capitalize(str) { | ||
return str.toUpperCase(); | ||
} |