Snowpack - Font URLs in CSS

10/17/2021, Sun
Categories: #shell #JavaScript
Tags: #NodeJs

Problem with URL Resolution

Up to Snowpack version 3.8.8, there is an issue with how Snowpack resolves path references inside CSS files. This often creates a problem when importing font files as mentioned on this page.

If you have installed a CSS bundle as a Npm module, you can work around this issue by defining a path which references the original location of the asset in the "node_modules" folder.

Using the installation of latex.css as an example, the configuration for "snowpack.config.js" will be:

// snowpack.config.js

module.exports = {
  mount: {
    'node_modules/latex.css/fonts': '/fonts'
  }
};

The font location is explicitly noted for Snowpack to resolve the font URL references in "latex.css".