Filter doesn't work

Open
#170 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
build-system

Research direction

Reproduce the issue with the listed dependencies, CSS import, and PostCSS config. Compare the filtered and unfiltered output, then trace how the postcss-url filter handles the .woff2 URLs. Done means the filtered run rewrites the font URL to the node_modules/@fontsource/raleway path shown in the expected output.

Written by the indexing model from the issue text.

Description

Dependencies:
  • "postcss-cli": "9.1.0",
  • "postcss-import": "14.0.2",
  • "postcss-url": "10.1.3"
  • "@fontsource/raleway": "4.5.0"
CSS Code
@import '@fontsource/raleway/variable.css';
PostCSS config
module.exports = {
  plugins: [
    require('postcss-import'),
    require('postcss-url')([
    {
      filter: '**/*.woff2',
      url: (asset) => {
        return `node_modules/@fontsource/raleway/${asset.url.replace('./', '')}`;
      }
    }
  ]
};
Error

Running the post CSS Cli return output containing the following part:

@font-face {
  font-family: 'RalewayVariable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('./files/raleway-cyrillic-variable-wghtOnly-normal.woff2') format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

If I remove the filter, I get the expected output:

@font-face {
  font-family: 'RalewayVariable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('node_modules/@fontsource/raleway/files/raleway-cyrillic-variable-wghtOnly-normal.woff2') format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
Dominant language
JavaScript
Stars
383
Forks
58
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from postcss/postcss-url

All issues in postcss/postcss-url

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.