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

Can't resolve absolute paths when prefixed with ~ in scss files #176

Open
juzerzarif opened this issue Jul 28, 2022 · 1 comment
Open

Can't resolve absolute paths when prefixed with ~ in scss files #176

juzerzarif opened this issue Jul 28, 2022 · 1 comment

Comments

@juzerzarif
Copy link

I have a font-face block as follows:

@font-face {
  font-family: 'FontAwesome';
  src: url('~font-awesome/fonts/fontawesome-webfont.eot?v=4.7.0');
  src: url('~font-awesome/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype');
  font-weight: normal;
  font-style: normal;
}

postcss-url can't seem to resolve ~font-awesome/fonts/fontawesome-webfont.eot to the correct node_modules path and resolves it relative to the scss file that's being transformed i.e. /Users/me/my-project/src/~font-awesome/fonts/fontawesome-webfont.eot which causes inlining to not work since there's no font file at that path.

Is there a way to have postcss-url resolve ~ prefixed paths from node_modules instead of relative to the scss file?

@RolKau
Copy link

RolKau commented Oct 5, 2023

You could use the rewrite functionality to insert the path to the module relative to the stylesheet:

import path from 'node:path';
import url from 'postcss-url';

url({
    filter: (asset) => /^~/.exec(asset.url),
    url: (asset, dir) => path.join(path.relative(dir.from, path.join(__dirname, 'node_modules')), asset.url.substr(1)),
})

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