Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
641 changes: 114 additions & 527 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"scripts": {
"dev": "nuxt dev playground",
"build": "nuxt-module-build",
"build": "rolli",
"build:play": "nuxt build playground",
"generate:play": "nuxt generate playground",
"preview:play": "nuxt preview playground",
Expand All @@ -39,13 +39,13 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@nuxt/module-builder": "^0.5.1",
"@types/node": "^20.5.9",
"@types/node": "^20.6.0",
"bummp": "^0.2.0",
"configshare": "^0.1.4",
"eslint": "^8.48.0",
"configshare": "^0.1.5",
"eslint": "^8.49.0",
"nuxt": "^3.7.1",
"prettier": "^3.0.3",
"rolli": "^0.6.0",
"typescript": "^5.1.6"
}
}
14 changes: 0 additions & 14 deletions playground/app.vue

This file was deleted.

6 changes: 6 additions & 0 deletions playground/components/NavMain.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<nav id="nav-main">
<NuxtLink to="/" style="margin-right: 1rem">Home</NuxtLink>
<NuxtLink to="/about">About</NuxtLink>
</nav>
</template>
28 changes: 28 additions & 0 deletions playground/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div id="__default">
<NavMain />
<slot />
</div>
</template>

<style>
body {
font-family: 'AspektaPRO-VF', sans-serif;
font-variation-settings: 'wght' 400;
background: #111;
color: #fff;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

h1 {
font-variation-settings: 'wght' 600;
}

a,
a:hover,
a:visited {
color: #fff;
text-decoration: none;
}
</style>
9 changes: 2 additions & 7 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ import Module from '../src/module'

export default defineNuxtConfig({
telemetry: false,
components: false,
imports: {
autoImport: false,
},

modules: [Module],

fontLoader: {
local: [
{
src: '/fonts/AspektaVF.woff2',
family: 'Aspekta Variable',
src: '/fonts/AspektaPRO-VF.woff2',
family: 'AspektaPRO-VF',
weight: '100 900',
class: 'font-aspekta',
},
],
},
Expand Down
5 changes: 5 additions & 0 deletions playground/pages/about/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div id="page-about">
<h1>About Page</h1>
</div>
</template>
5 changes: 5 additions & 0 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div id="page-index">
<h1>Index Page</h1>
</div>
</template>
49 changes: 49 additions & 0 deletions rolli.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { defineConfig } from 'rolli'
import pkg from './package.json' assert { type: 'json' }
import {
generateModuleMeta,
generateModuleTypes,
logModuleTemplates,
} from './src/utils/templates.js'

export default defineConfig({
tsconfig: 'playground/.nuxt/tsconfig.json',
exports: false,
bin: false,

entries: [
// Module Core
{
input: './src/module.ts',
output: './dist/module.mjs',
externals: [/@nuxt/],
replace: {
preventAssignment: true,
__name__: pkg.name,
__version__: pkg.version,
},
},
{
input: './src/types/module.ts',
output: './dist/module.d.ts',
},
// Runtime Composables
{
input: './src/runtime/composables/index.ts',
output: './dist/runtime/composables/index.mjs',
externals: ['#imports'],
},
{
input: './src/types/runtime/composables/index.ts',
output: './dist/runtime/composables/index.d.ts',
},
],

hooks: {
'rolli:end': async () => {
await generateModuleMeta(pkg.name, pkg.version)
await generateModuleTypes()
logModuleTemplates()
},
},
})
6 changes: 6 additions & 0 deletions src/meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const name = '__name__'
export const version = '__version__'
export const configKey = 'fontLoader'
export const compatibility = {
nuxt: '>=3.0.0',
}
16 changes: 7 additions & 9 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { defineNuxtModule, createResolver, addImports } from '@nuxt/kit'
import { generateStyles, parseFormat } from './runtime/utils'
import type { ModuleOptions } from './types'

export * from './types'
import { generateStyles, parseFormat } from './utils'
import { name, version, configKey, compatibility } from './meta'
import type { ModuleOptions } from './types/module'

export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'nuxt-font-loader',
configKey: 'fontLoader',
compatibility: {
nuxt: '>=3.0.0',
},
name,
version,
configKey,
compatibility,
},

defaults: {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './useExternalFont'
export * from './useLocalFont'
export * from './use-external-font'
export * from './use-local-font'
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { useHead } from '#imports'
import { generateStyles } from '../utils'
import type { ExternalOptions } from '../../types'
import { generateStyles } from '../../utils'
import type { ExternalOptions } from '../../types/options'

/**
* Loads fonts directly from third-party servers.
*
* @example
*
* ```js
* useExternalFont([
* {
* src: 'path-to-external-source'
* }
* ])
* ```
*
* @since 2.2.0
*/
export const useExternalFont = (external: ExternalOptions[]) => {
const { classes, root } = generateStyles(external)
const styles = `${classes}${root}`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import { useHead } from '#imports'
import { generateStyles, parseFormat } from '../utils'
import type { LocalOptions } from '../../types'
import { generateStyles, parseFormat } from '../../utils'
import type { LocalOptions } from '../../types/options'

/**
* Loads fonts from the same domain as your deployment.
*
* At the moment, this is the most recommended method for handling fonts.
*
* @example
*
* ```js
* useLocalFont([
* {
* src: '/fonts/AspektaVF.woff2',
* family: 'Aspekta Variable',
* weight: '100 900'
* }
* ])
* ```
*
* @since 2.2.0
*/
export const useLocalFont = (local: LocalOptions[]) => {
const { fontFace, classes, root } = generateStyles(local)
const styles = `${fontFace}${classes}${root}`
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/utils/index.ts

This file was deleted.

33 changes: 5 additions & 28 deletions src/types/module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { LocalOptions, ExternalOptions } from './index'
import type { NuxtModule } from '@nuxt/schema'
import type { LocalOptions, ExternalOptions } from './options'

/**
* Module Options.
*
* @since 2.0.0
*/
export interface ModuleOptions {
/**
* An array of objects that specifies `local` font sources.
Expand Down Expand Up @@ -66,25 +62,6 @@ export interface ModuleOptions {
autoImport?: boolean
}

declare module '@nuxt/schema' {
interface NuxtConfig {
/**
* Nuxt Font Loader
*
* Simple, modern and lightweight font loader for Nuxt.
*
* @see [source](https://github.com/ivodolenc/nuxt-font-loader)
*/
fontLoader?: ModuleOptions
}
interface NuxtOptions {
/**
* Nuxt Font Loader
*
* Simple, modern and lightweight font loader for Nuxt.
*
* @see [source](https://github.com/ivodolenc/nuxt-font-loader)
*/
fontLoader?: ModuleOptions
}
}
declare const module: NuxtModule<ModuleOptions>

export { module as default }
5 changes: 0 additions & 5 deletions src/types/external.ts → src/types/options/external.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External Options.
*
* @since 2.1.0
*/
export interface ExternalOptions {
/**
* Specifies path to the external source.
Expand Down
1 change: 0 additions & 1 deletion src/types/index.ts → src/types/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './external'
export * from './local'
export * from './module'
5 changes: 0 additions & 5 deletions src/types/local.ts → src/types/options/local.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Local Options.
*
* @since 2.0.0
*/
export interface LocalOptions {
/**
* Specifies path to the font file.
Expand Down
2 changes: 2 additions & 0 deletions src/types/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './use-external-font'
export * from './use-local-font'
18 changes: 18 additions & 0 deletions src/types/runtime/composables/use-external-font.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ExternalOptions } from '../../options'

/**
* Loads fonts directly from third-party servers.
*
* @example
*
* ```js
* useExternalFont([
* {
* src: 'path-to-external-source'
* }
* ])
* ```
*
* @since 2.2.0
*/
export declare const useExternalFont: (external: ExternalOptions[]) => any
22 changes: 22 additions & 0 deletions src/types/runtime/composables/use-local-font.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { LocalOptions } from '../../options'

/**
* Loads fonts from the same domain as your deployment.
*
* At the moment, this is the most recommended method for handling fonts.
*
* @example
*
* ```js
* useLocalFont([
* {
* src: '/fonts/AspektaVF.woff2',
* family: 'Aspekta Variable',
* weight: '100 900'
* }
* ])
* ```
*
* @since 2.2.0
*/
export declare const useLocalFont: (local: LocalOptions[]) => any
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseFormat } from './parseFormat'
import type { LocalOptions, ExternalOptions } from '../../types'
import { parseFormat } from './parse-format'
import type { LocalOptions, ExternalOptions } from '../types/options'

/**
* Generates head styles from options entered by the user.
Expand Down
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './generate-styles'
export * from './parse-format'
File renamed without changes.
Loading