npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

google-fonts-plugin

4.0.2 • Public • Published

Google Fonts Plugin

GitHub license npm CircleCI Codecov

Webpack plugin that downloads fonts from Google Fonts and encodes them to base64.

Supports various font formats, currently eot, ttf, woff and woff2.

Exports to format specific and minified css files, which you can serve to your clients.

Note: Current version works with Webpack 4. For webpack 3, use version 1.0.3

Install

npm i -D google-fonts-plugin

Usage

webpack.config.js
const GoogleFontsPlugin = require('google-fonts-plugin')
 
module.exports = {
  plugins: {
    new GoogleFontsPlugin({
        /* options */
    })
  }
}
webpack.config.js
const GoogleFontsPlugin = require('google-fonts-plugin')
 
module.exports = {
  plugins: {
    new GoogleFontsPlugin('path/to/config.json')
  }
}

Options

Plugin supports configuration in javascript object, json or neon file and also in your package.json.

Name Type Default Description
fonts Font[] Roboto Defines which fonts and it's variants and subsets to download
formats String[] eot, ttf, woff, woff2 Specifies which formats to download
encode Boolean true Whether should encode to base64
cache Boolean true Whether FS caching should be checked before sending requests
Font object
Name Type Default Description
family String Roboto Sets the font family
variants String[] 400, 400i, 700, 700i Sets the variants of the font family to download, note that not all fonts have the all the possible variants
subsets String[] latin-ext Sets the subsets, note that not all fonts are available in all subsets

Example configuration

config.json
{
    "google-fonts-plugin": {
        "fonts": [
            {
                "family": "Roboto",
                "variants": [
                    "400",
                    "400i",
                    "700",
                    "700i"
                ],
                "subsets": [
                    "latin-ext"
                ]
            }
        ],
        "formats": [
            "woff",
            "woff2"
        ]
    }
}
config.neon
google-fonts-plugin:
    fonts: 
        - 
            family: Roboto
            variants:
                - 400
                - 400i
                - 700
                - 700i
            subsets:
                - latin-ext
    formats: 
        - woff
        - woff2

Note: For Google's material icons, simply set Material Icons as font-family

install

npm i google-fonts-plugin

Downloadsweekly downloads

4,083

version

4.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability