Skip to content

Commit

Permalink
feat!: migrate plugin to unplugin
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- rename virtual "virtual:fonts.css" to "unfonts.css"
- rename package "vite-plugin-fonts" to "unplugin-fonts"
  • Loading branch information
stafyniaksacha committed Mar 19, 2023
1 parent 9714960 commit 5ae235a
Show file tree
Hide file tree
Showing 48 changed files with 8,395 additions and 1,865 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
*.snap
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-workspace-root-check=true
shamefully-hoist=true
2 changes: 0 additions & 2 deletions example/main.ts

This file was deleted.

19 changes: 19 additions & 0 deletions examples/astro/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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': './public/assets/fonts/DancingScript*',
},
},
})
],
})
15 changes: 15 additions & 0 deletions examples/astro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "astro-test",
"private": true,
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"devDependencies": {
"astro": "^2.1.3",
"unplugin-fonts": "workspace:*"
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions examples/astro/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="astro/client" />
30 changes: 30 additions & 0 deletions examples/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
// import "/@unplugin-fonts/fonts.css";
---

<div>
<h1>Hello Astro!</h1>
<h2>I'm using a local font !</h2>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
</div>

<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;
}
</style>
16 changes: 16 additions & 0 deletions examples/astro/tsconfig.json
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
}
}
9 changes: 9 additions & 0 deletions examples/nuxt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
*.log*
.nuxt
.nitro
.cache
.output
.env
dist
.DS_Store
26 changes: 26 additions & 0 deletions examples/nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<h1>Hello Nuxt!</h1>
<h2>I'm using a local font !</h2>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
</template>

<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;
}
</style>
Binary file added examples/nuxt/assets/fonts/DancingScript-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Unfonts from '../../src/nuxt'

export default defineNuxtConfig({
modules: [
Unfonts,
],
fonts: {
google: {
families: ['Crimson Pro', 'Open Sans', 'Material+Icons'],
},

custom: {
display: 'swap',
families: {
'Dancing Script': './assets/fonts/DancingScript*',
},
},
}
})
13 changes: 13 additions & 0 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "nuxt-test",
"private": true,
"scripts": {
"dev": "nuxt dev",
"build": "nuxt build",
"preview": "nuxt preview"
},
"devDependencies": {
"nuxt": "^3.3.1",
"unplugin-fonts": "workspace:*"
}
}
4 changes: 4 additions & 0 deletions examples/nuxt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
Binary file added examples/vite/assets/fonts/DancingScript-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion example/index.html → examples/vite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</head>
<body>
<h1>Hello Vite!</h1>
<h2>I'm using a local font !</h2>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
<h3>I'm using a local font !</h3>
<script type="module" src="/main.ts"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions examples/vite/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'unfonts.css'
import './style.css'
6 changes: 3 additions & 3 deletions example/package.json → examples/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "vite-test",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^2.9.12",
"vite-plugin-fonts": "workspace: *"
"vite": "^4.2.0",
"unplugin-fonts": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion example/style.css → examples/vite/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ a {
font-family: "Open Sans", Avenir, Helvetica, Arial, sans-serif;
}

h3 {
h2 {
font-family: "Dancing Script", sans-serif;
font-size: 3rem;
font-weight: 600;
Expand Down
5 changes: 3 additions & 2 deletions example/vite.config.ts → examples/vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { defineConfig } from 'vite'
import ViteFonts from 'vite-plugin-fonts'
import Unfonts from '../../src/vite'

export default defineConfig({
plugins: [
ViteFonts({
Unfonts({
google: {
families: ['Crimson Pro', 'Open Sans', 'Material+Icons'],
},

custom: {
display: 'swap',
families: {
'Dancing Script': './assets/fonts/DancingScript*',
},
Expand Down
91 changes: 78 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,103 @@
{
"name": "vite-plugin-fonts",
"name": "unplugin-fonts",
"version": "0.7.0",
"description": "Webfont loader for vite",
"author": "stafyniaksacha",
"license": "MIT",
"repository": "stafyniaksacha/vite-plugin-fonts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./astro": {
"types": "./dist/astro.d.ts",
"require": "./dist/astro.js",
"import": "./dist/astro.mjs"
},
"./esbuild": {
"types": "./dist/esbuild.d.ts",
"require": "./dist/esbuild.js",
"import": "./dist/esbuild.mjs"
},
"./nuxt": {
"types": "./dist/nuxt.d.ts",
"require": "./dist/nuxt.js",
"import": "./dist/nuxt.mjs"
},
"./rollup": {
"types": "./dist/rollup.d.ts",
"require": "./dist/rollup.js",
"import": "./dist/rollup.mjs"
},
"./types": {
"types": "./dist/types.d.ts",
"require": "./dist/types.js",
"import": "./dist/types.mjs"
},
"./vite": {
"types": "./dist/vite.d.ts",
"require": "./dist/vite.js",
"import": "./dist/vite.mjs"
},
"./webpack": {
"types": "./dist/webpack.d.ts",
"require": "./dist/webpack.js",
"import": "./dist/webpack.mjs"
},
"./*": "./*"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"./dist/*",
"./*"
]
}
},
"files": [
"dist"
],
"scripts": {
"dev": "npm run build -- --watch",
"example:dev": "npm -C example run dev",
"example:build": "npm -C example run build",
"example:preview": "npm -C example run preview",
"build": "tsup src/index.ts --dts --format cjs,esm",
"build": "tsup",
"dev": "tsup --watch src",
"build:fix": "esno scripts/postbuild.ts",
"example:dev": "npm -C examples/vite run dev",
"example:build": "npm -C examples/vite run build",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
},
"peerDependencies": {
"@nuxt/kit": "^3.0.0",
"vite": "^2.0.0 || ^3.0.0 || ^4.0.0"
},
"peerDependenciesMeta": {
"@nuxt/kit": {
"optional": true
}
},
"dependencies": {
"fast-glob": "^3.2.11"
"fast-glob": "^3.2.12",
"unplugin": "^1.3.1"
},
"devDependencies": {
"@antfu/eslint-config-ts": "^0.25.1",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"eslint": "^8.18.0",
"@antfu/eslint-config-ts": "^0.36.0",
"@nuxt/kit": "^3.3.1",
"@types/node": "^18.15.3",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"chalk": "^5.2.0",
"eslint": "^8.36.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"tsup": "^6.1.2",
"typescript": "^4.7.4",
"vite": "^2.9.12"
"esno": "^0.16.3",
"pathe": "^1.1.0",
"rollup": "^3.19.1",
"tsup": "^6.6.3",
"typescript": "^5.0.2",
"vite": "^4.2.0",
"webpack": "^5.76.2"
}
}
Loading

0 comments on commit 5ae235a

Please sign in to comment.