Giter Site home page Giter Site logo

Comments (4)

haunted-loaf avatar haunted-loaf commented on June 18, 2024 1

I encountered the same issue.

I don't understand why the default export doesn't work, but using the named export worked for me:

import { VitePluginFonts } from 'vite-plugin-fonts'

export default {
  plugins: [
    VitePluginFonts({
      google: {
        families: ['Source Sans Pro'],
      },
    }),
  ],
}

from unplugin-fonts.

stafyniaksacha avatar stafyniaksacha commented on June 18, 2024 1

From looking at the index.ts, VitePluginFonts is exported as the default and ViteFonts isn't exported at all (see below).

Hum, that's wired, the default export should work, maybe it's related to https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports

Updating the examples to reflect the right import should address the issue and I don't mind doing it/submitting a PR. For the maintainers, if you would prefer I don't or want to handle it differently, just let me know!

I updated the readme to use the named export, which should work in any cases!
Thanks for the feedback!

from unplugin-fonts.

tbusillo avatar tbusillo commented on June 18, 2024

Experienced the same and as @haunted-loaf mentioned, using VitePluginFonts as a named import worked.

From looking at the index.ts, VitePluginFonts is exported as the default and ViteFonts isn't exported at all (see below).

export {
  VitePluginFonts,
  VitePluginFontsOptions,
}
export default VitePluginFonts

However, the examples in the README all import and make use of ViteFonts, such as in the below.

https://github.com/stafyniaksacha/vite-plugin-fonts/blob/598594bd17ae26050b0d882c56ed827c739247b6/README.md?plain=1#L11-L26)

Updating the examples to reflect the right import should address the issue and I don't mind doing it/submitting a PR. For the maintainers, if you would prefer I don't or want to handle it differently, just let me know!

from unplugin-fonts.

tbusillo avatar tbusillo commented on June 18, 2024

Ah, that's a good catch and may be the issue because you're right, for the default export it shouldn't really matter what you call it when importing it, so long as its being exported. Thinking about it, I think its less of a matter of there not being a default and more that it's not being interpreted/identifiable as a function. I'm not sure why that's the case, but it may have to do with when and/or how the type definitions are being generated via dts when the plugin is built.

Thanks for being so responsive and in case it helps, this is what index.d.ts looks like in dist after build:

declare function VitePluginFonts(options?: VitePluginFontsOptions): Plugin;

export { VitePluginFonts, VitePluginFontsOptions, VitePluginFonts as default };

from unplugin-fonts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.