Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font defined in @nuxt/fonts module does not load #803

Open
VladimirCores opened this issue Oct 7, 2024 · 2 comments
Open

Font defined in @nuxt/fonts module does not load #803

VladimirCores opened this issue Oct 7, 2024 · 2 comments
Labels
type: bug Something isn't working

Comments

@VladimirCores
Copy link

Environment

Nuxt project info:


  • Operating System: Linux
  • Node Version: v20.17.0
  • Nuxt Version: 3.13.2
  • CLI Version: 3.14.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-cfhpv1?file=package.json,nuxt.config.ts

Describe the bug

Font loaded dynamically and embeded from nuxt.config wont be loaded.
Image

Additional context

No response

@VladimirCores VladimirCores added the type: bug Something isn't working label Oct 7, 2024
@screeny05
Copy link

You can add the following to .storybook/middleware.js:

const createNuxtProxy = (router, path) => {
  router.use(
    path,
    proxy.createProxyMiddleware({
      target: `http://localhost:3000/${path}`,
      changeOrigin: true,
      pathRewrite: {
        [`^${path}`]: '',
      },
    })
  );
};

module.exports = (router) => {
  createNuxtProxy(router, '/_fonts');
};

This solves the problem for running storybook locally. Unfortunately i have not yet been able to figure out how to include the fonts in a storybook-build.

@screeny05
Copy link

screeny05 commented Dec 24, 2024

Actually i found a way to include the fonts in storybook-builds like chromatic as well.

To do this you have to import the _fonts-folder from the built nuxt-project itself.

In package.json:

{
  "scripts": {
    "build": "nuxt build",
    "chromatic": "pnpm build && chromatic --project-token=xxx"
  }
}

In .storybook/main.ts:

import fs from 'fs';

const config: StorybookConfig = {
  /** [...] */
  staticDirs: [
    ...(fs.existsSync(__dirname + '/../.output/public/_fonts') ? [{ from: '../.output/public/_fonts', to: '/_fonts' }] : [])
  ],
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants