npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-fontpath

v1.0.0

Published

PostCSS plugin that adds a font-path attribute to @font-face which expands to the FontSpring syntax

Downloads

30,703

Readme

PostCSS Fontpath

NPM version Build Status Dependency Status

PostCSS plugin that automatically generates src values for @font-face rules based on the path to your font files. You can manually provide the types of sources to output, or automatically generate sources based on the font files that actually exist in your project.

Part of Rucksack - CSS Superpowers

Input

@font-face {
  font-family: 'My Font';
  font-path: '/path/to/font/file';
  font-weight: normal;
  font-style: normal;
}

Output

@font-face {
  font-family: 'My Font';
  src: url("/path/to/font/file.eot") format('embedded-opentype'),
       url("/path/to/font/file.woff") format('woff2'),
       url("/path/to/font/file.woff") format('woff'),
       url("/path/to/font/file.ttf") format('truetype'),
       url("/path/to/font/file.svg") format('svg');
  font-weight: normal;
  font-style: normal;
}

Usage

var fontpath = require('postcss-fontpath');

postcss([ fontpath({ ... }) ]);

See PostCSS docs for examples for your environment.

Formats

By default postcss-fontpath generates src values for all valid font types. You can change the default sources generated by providing an array of custom src formats in the formats option. Each format requires a type and a file extension to map to. The order of the formats in the array determines the ordering of the src values outputted.

{
  formats: [
    { type: 'woff2', ext: 'woff2' },
    { type: 'embedded-opentype', ext: 'eot' }
  ]
}

File checking

Postcss-fontpath can automatically check the path you give it and only generate src values for the files that actually exist in your project with the checkFiles option.

Remember that postcss-fontpath checks paths based on your current directory structure - if your production environment differs from your development setup (eg: transformed in a buildstep) then this method could result in incorrect declarations

IE8 support

If you need to support IE8 (which doesn't support multiple src values or format()), postcss-fontpath can generate a FontSpring style IE8 hack with the ie8Fix option, resulting in an output like this

@font-face {
  font-family: 'My Font';
  src: url("/path/to/font/file.eot");
  src: url("/path/to/font/file.eot?#iefix") format('embedded-opentype'),
       url("/path/to/font/file.woff") format('woff2'),
       ...
  font-weight: normal;
  font-style: normal;
}

Options

Option | Type | Default | Description
------------ | ------- | ------- | -----------
formats | Array | [ { type: 'embedded-opentype', ext: 'eot' }, { type: 'woff2', ext: 'woff2' }, { type: 'woff', ext: 'woff' }, { type: 'truetype', ext: 'ttf' }, { type: 'svg', ext: 'svg'} ] | Default font formats to generate src values for
checkFiles | Boolean | false | Whether to generate src values based on the font files that actually exist at the given font-path ie8Fix | Boolean | false | Whether to generate a hack for IE8 support


MIT © Sean King