-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve local file preload for vite and vitepress
- Loading branch information
1 parent
a17831d
commit 10d7067
Showing
24 changed files
with
2,318 additions
and
62 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,41 @@ | ||
import { defineConfig } from 'astro/config' | ||
import Unfonts from 'unplugin-fonts/astro' | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
Unfonts({ | ||
google: { | ||
families: ['Crimson Pro', 'Open Sans', 'Material+Icons'], | ||
}, | ||
|
||
custom: { | ||
display: 'swap', | ||
families: { | ||
'Dancing Script': { | ||
src: './public/assets/fonts/DancingScript*', | ||
transform(font) { | ||
if (font.basename === 'DancingScript-Bold') | ||
font.weight = 700 | ||
|
||
return font | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
fontsource: { | ||
families: [ | ||
{ | ||
name: 'ABeeZee', | ||
weights: [400], | ||
styles: ['italic'], | ||
}, | ||
{ | ||
name: 'Truculenta', | ||
weights: [400, 700], | ||
}, | ||
], | ||
}, | ||
}), | ||
], | ||
}) |
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,17 @@ | ||
{ | ||
"name": "astro-test", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"start": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro" | ||
}, | ||
"devDependencies": { | ||
"@fontsource/abeezee": "^4.5.10", | ||
"@fontsource/truculenta": "^4.5.12", | ||
"astro": "^3.5.5", | ||
"unplugin-fonts": "workspace:*" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ | ||
/// <reference types="astro/client" /> |
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,45 @@ | ||
--- | ||
import Unfont from 'unplugin-fonts/astro/component.astro'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<Unfont /> | ||
</head> | ||
<body> | ||
<h1>Hello Astro!</h1> | ||
<h2>I'm using a local font !</h2> | ||
<div class="fontsource-abeezee">I'm a ABeeZee fontsource</div> | ||
<div class="fontsource-truculenta">I'm a Truculenta fontsource</div> | ||
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a> | ||
</body> | ||
</html> | ||
|
||
<style> | ||
body { | ||
font-family: "Crimson Pro", Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
|
||
a { | ||
font-family: "Open Sans", Avenir, Helvetica, Arial, sans-serif; | ||
} | ||
|
||
h2 { | ||
font-family: "Dancing Script", sans-serif; | ||
font-size: 3rem; | ||
font-weight: 600; | ||
} | ||
|
||
.fontsource-abeezee { | ||
font-family: "ABeeZee", sans-serif; | ||
} | ||
|
||
.fontsource-truculenta { | ||
font-family: "Truculenta", sans-serif; | ||
} | ||
</style> |
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,45 @@ | ||
--- | ||
import Unfont from 'unplugin-fonts/astro/component.astro'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<Unfont /> | ||
</head> | ||
<body> | ||
<h1>Hello Astro!</h1> | ||
<h2>I'm using a local font in a subfolder !</h2> | ||
<div class="fontsource-abeezee">I'm a ABeeZee fontsource</div> | ||
<div class="fontsource-truculenta">I'm a Truculenta fontsource</div> | ||
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a> | ||
</body> | ||
</html> | ||
|
||
<style> | ||
body { | ||
font-family: "Crimson Pro", Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
|
||
a { | ||
font-family: "Open Sans", Avenir, Helvetica, Arial, sans-serif; | ||
} | ||
|
||
h2 { | ||
font-family: "Dancing Script", sans-serif; | ||
font-size: 3rem; | ||
font-weight: 600; | ||
} | ||
|
||
.fontsource-abeezee { | ||
font-family: "ABeeZee", sans-serif; | ||
} | ||
|
||
.fontsource-truculenta { | ||
font-family: "Truculenta", sans-serif; | ||
} | ||
</style> |
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,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "preserve", | ||
// Enable top-level await, and other modern ESM features. | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
// Enable node-style module resolution, for things like npm package imports. | ||
"moduleResolution": "node", | ||
// Enable JSON imports. | ||
"resolveJsonModule": true, | ||
// Enable stricter transpilation for better output. | ||
"isolatedModules": true, | ||
// Astro will directly run your TypeScript code, no transpilation needed. | ||
"noEmit": true | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<h1>Hello Vite!</h1> | ||
<h2>I'm using a local font !</h2> | ||
<div class="fontsource-abeezee">I'm a ABeeZee fontsource</div> | ||
<div class="fontsource-truculenta">I'm a Truculenta fontsource</div> | ||
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a> | ||
<script type="module" src="/main.ts"></script> | ||
</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,2 @@ | ||
import 'unfonts.css' | ||
import './style.css' |
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,16 @@ | ||
{ | ||
"name": "vite-test", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"@fontsource/abeezee": "^4.5.10", | ||
"@fontsource/truculenta": "^4.5.12", | ||
"unplugin-fonts": "workspace:*", | ||
"vite": "^5.0.0" | ||
} | ||
} |
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,27 @@ | ||
body { | ||
font-family: "Crimson Pro", Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
|
||
a { | ||
font-family: "Open Sans", Avenir, Helvetica, Arial, sans-serif; | ||
} | ||
|
||
h2 { | ||
font-family: "Dancing Script", sans-serif; | ||
font-size: 3rem; | ||
font-weight: 600; | ||
} | ||
|
||
|
||
.fontsource-abeezee { | ||
font-family: "ABeeZee", sans-serif; | ||
} | ||
|
||
.fontsource-truculenta { | ||
font-family: "Truculenta", sans-serif; | ||
} |
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,41 @@ | ||
import { defineConfig } from 'vite' | ||
import Unfonts from '../../src/vite' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
Unfonts({ | ||
google: { | ||
families: ['Crimson Pro', 'Open Sans', 'Material+Icons'], | ||
}, | ||
|
||
custom: { | ||
display: 'swap', | ||
families: { | ||
'Dancing Script': { | ||
src: './assets/fonts/DancingScript*', | ||
transform(font) { | ||
if (font.basename === 'DancingScript-Bold') | ||
font.weight = 700 | ||
|
||
return font | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
fontsource: { | ||
families: [ | ||
{ | ||
name: 'ABeeZee', | ||
weights: [400], | ||
styles: ['italic'], | ||
}, | ||
{ | ||
name: 'Truculenta', | ||
weights: [400, 700], | ||
}, | ||
], | ||
}, | ||
}), | ||
], | ||
}) |
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
Oops, something went wrong.