nuxt-font-loader-strategy
nuxt-font-loader-strategy copied to clipboard
How to import fonts from node_modules?
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?
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 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.
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.
The files are available in the node_modules?
@ThornWalli yes, @foo/core-styles
is in node_modules. Perhaps the @
is the problem in a scoped npm package name.
@rwwagner90 I have applied the change for importPathResolve
. Now all require calls are made by ~ .
So it should be finished?
@ThornWalli I am not sure. If you want to release a new version, I can try it out.
Looks like a new version was released. I will try it out soon.