nuxt-font-loader-strategy icon indicating copy to clipboard operation
nuxt-font-loader-strategy copied to clipboard

How to import fonts from node_modules?

Open RobbieTheWagner opened this issue 4 years ago • 7 comments

I've been trying a bunch of different ~, @/, node_modules, /node_modules etc and I cannot seem to import fonts from node_modules. How do I do this?

RobbieTheWagner avatar Jan 28 '21 02:01 RobbieTheWagner

Do you have an example dependency?

I think the webpack loader e.g. url-loader has no access to the node_modules directory. Fonts are resolved per require.

ThornWalli avatar Jan 28 '21 22:01 ThornWalli

@ThornWalli we ended up needing:

 importPathResolve: (file) => {
   return `~${file}`
 },

This allowed a src like src: '@foo/core-styles/assets/fonts/Serif', to work, where @foo/core-styles is a package in node_modules.

With that importPathResolve it fixed the path so it worked for all cases.

RobbieTheWagner avatar Jan 29 '21 01:01 RobbieTheWagner

I created a package with fonts and was able to integrate it without problems. (https://github.com/ThornWalli/test-font)

In that case no prefix is used.

image

The files are available in the node_modules?

ThornWalli avatar Jan 29 '21 09:01 ThornWalli

@ThornWalli yes, @foo/core-styles is in node_modules. Perhaps the @ is the problem in a scoped npm package name.

RobbieTheWagner avatar Jan 29 '21 13:01 RobbieTheWagner

@rwwagner90 I have applied the change for importPathResolve. Now all require calls are made by ~ .

So it should be finished?

ThornWalli avatar Jan 29 '21 20:01 ThornWalli

@ThornWalli I am not sure. If you want to release a new version, I can try it out.

RobbieTheWagner avatar Jan 30 '21 18:01 RobbieTheWagner

Looks like a new version was released. I will try it out soon.

RobbieTheWagner avatar Jan 30 '21 18:01 RobbieTheWagner