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

How to import fonts from node_modules? #152

Open
RobbieTheWagner opened this issue Jan 28, 2021 · 7 comments
Open

How to import fonts from node_modules? #152

RobbieTheWagner opened this issue Jan 28, 2021 · 7 comments

Comments

@RobbieTheWagner
Copy link

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?

@ThornWalli
Copy link
Contributor

ThornWalli commented Jan 28, 2021

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.

@RobbieTheWagner
Copy link
Author

@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.

@ThornWalli
Copy link
Contributor

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?

@RobbieTheWagner
Copy link
Author

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

@ThornWalli
Copy link
Contributor

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

So it should be finished?

@RobbieTheWagner
Copy link
Author

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

@RobbieTheWagner
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants