Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Using null-loader to remove/skip fonts specified using url() will corrupt the generated .css file #17

@cyparu

Description

@cyparu

In my project I'm using Font-Awessome (with scss-loader + file-loader) .... and everything goes fine, and the fonts are put into the proper directory. But I'm looking to "remove some fat" and keep just the .*woff2 files from all of font formats.

I've tried to use "null-loader" to "skip" all other fonts {test: /.(woff|eot|ttf|otf|svg)$/, use: "null-loader"} ... but while the font files are removed, this will corrupt the url() declaration into the generated css file resulting in url([object Object ]) kind of source ...

  • Operating System: Windows
  • Node Version: 9.11.1
  • NPM Version: 5.8.0
  • webpack Version: 4.6.0
  • null-loader Version: 0.1.1

This issue is for a:

  • bug
  • feature request
  • modification request

Code

webpack.config.js
  // try to keep just woff2 font and remove all the others
  {  test: /\.woff2$/,  use: "file-loader?name=fonts/[name].[ext]" },
  {  test: /\.(woff|eot|ttf|otf|svg)$/,  use: "null-loader" }

Expected Behavior

  1. The fonts folder should include just fontawesome-webfont.woff2
  2. The generated .css should include just the src: url(fonts/fontawesome-webfont.woff2) format("woff2") declaration:
@font-face {
  font-family: 'FontAwesome';
  src: url(fonts/fontawesome-webfont.woff2) format("woff2")
  font-weight: normal;
  font-style: normal;
}

Actual Behavior

  1. This is 🆗 , so just the woff2 font file will be copied
  2. The generated .css will include for ALL non skipped formats an odd url name ( url([object Object]) ) instead of removing the declaration
@font-face {
  font-family: 'FontAwesome';
  src: url([object Object]);
  src: url([object Object]) format("embedded-opentype"), url(fonts/fontawesome-webfont.woff2) format("woff2"), url([object Object]) format("woff"), url([object Object]) format("truetype"), url([object Object]) format("svg");
  font-weight: normal;
  font-style: normal;
}

How Do We Reproduce?

The project reproducing this issue is located here: http://www.github.com/cyparu/null_loader_css_url_bug

Steps to execute:

yarn
yarn build

check build/index.css for wrongly generated CSS content

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions