-
Notifications
You must be signed in to change notification settings - Fork 58
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
copy fonts #121
Comments
Here's what I use. First, I require typeface fonts from npm (e.g., https://yarnpkg.com/en/package/typeface-roboto). Then I configure the task as follows:
This puts the fonts into the "font" folder inside the dest directory, where I can bundle them with my app. |
@mojavelinux a little bit tricky but very helpful! Kudo. One note, please add that you use |
I think we should write @mojavelinux solution in Readme, somewhere. Thanks @mojavelinux. |
I think this qualifies as a bug. Enabling the module.exports = {
// inherited 'to' from the postcss-cli command flags
plugins: [
require('postcss-import')(),
require('postcss-url')({
url: 'copy',
assetsPath: 'static',
useHash: true,
}),
...otherPlugins,
],
} Imported files were copied to the |
On top of @mojavelinux 's solution I had to ensure Is there any way to get the PostCSS |
Here's what I did: postcssUrl([
{
url: (asset) => {
const relpath = asset.pathname.substr(1)
const abspath = require.resolve(relpath)
const basename = ospath.basename(abspath)
const destpath = ospath.join(dest, 'font', basename)
if (!fs.pathExistsSync(destpath)) fs.copySync(abspath, destpath)
return path.join('..', 'font', basename)
},
},
]), (I just realized I shared exactly the same snippet above). |
@mojavelinux maybe I miss something here, but where does |
It's the value passed into the function that is handling writing the processed CSS. In my case, I'm using postCSS in a vinyl-fs pipeline. So dest is the vinyl-fs dest target. |
@mojavelinux |
Hi, i know that you do not encourage the use of copy, but i have a tricky need.
I have a node_module with a css file and relative font urls :
@font-face{font-family:"Avenir";src:url("./fonts/avenir-lighter.woff") format("woff")}
My app uses Nextjs and with style-loader + css-loader, my css module is well integrated to the output /.next/static/style.css but font files url are not copied magically to that folder.
So i want to use postcss-url to copy all fonts files to /.next/static/ and adapt url to point to that files.
I try that :
Sadly, it doesn't work and i get the following error :
These relative modules were not found:
Have you got any idea ?
Thx
The text was updated successfully, but these errors were encountered: