All Projects → AaronJan → postcss-font-grabber

AaronJan / postcss-font-grabber

Licence: Apache-2.0 License
A postcss plugin, it grabs remote font files and update your CSS, just like that.

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to postcss-font-grabber

Front End Tooling Recipes
Collection of pre-configured front-end tooling setups for common uses.
Stars: ✭ 176 (+576.92%)
Mutual labels:  gulp, postcss, rollup
rollup-plugin-sizes
Rollup plugin to display bundle contents & size information
Stars: ✭ 77 (+196.15%)
Mutual labels:  metadata, rollup, rollup-plugin
postcss-font-pack
PostCSS plugin to simplify font declarations by validating only configured font packs are used and adding fallbacks.
Stars: ✭ 18 (-30.77%)
Mutual labels:  font, postcss
rollup-plugin-collect-sass
Collect Sass, then compile
Stars: ✭ 17 (-34.62%)
Mutual labels:  rollup, rollup-plugin
Carbon.Gulp
Carbon/Gulp is a delicious blend of tasks and build tools poured into Gulp to form a full-featured modern asset pipeline for Flow Framework and Neos CMS.
Stars: ✭ 15 (-42.31%)
Mutual labels:  gulp, postcss
prepublish
Simplifies the prepare step (bundling, transpiling, rebasing) during publishing NPM packages.
Stars: ✭ 21 (-19.23%)
Mutual labels:  postcss, rollup
bymattlee-11ty-starter
A starter boilerplate powered by 11ty, Sanity, Gulp, Tailwind CSS, rollup.js, Alpine.js and Highway.
Stars: ✭ 27 (+3.85%)
Mutual labels:  gulp, rollup
rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
Stars: ✭ 52 (+100%)
Mutual labels:  rollup, rollup-plugin
mark.js
mark.js用于标记选中的文字,自定义插入标签
Stars: ✭ 27 (+3.85%)
Mutual labels:  gulp, rollup
rollup-plugin-tagged-template
Use plain HTML files as tagged templates.
Stars: ✭ 24 (-7.69%)
Mutual labels:  rollup, rollup-plugin
rollup-loader
Rollup does what it can do, and let Webpack finish the job.
Stars: ✭ 86 (+230.77%)
Mutual labels:  rollup, loader
angular-gulp-starter
Simple dev/prod build for Angular (2+) using gulp, systemjs, rollup, ngc (AOT), scss, Visual Studio
Stars: ✭ 18 (-30.77%)
Mutual labels:  gulp, rollup
rollup-plugin-external-globals
Transform external imports into global variables like output.globals.
Stars: ✭ 57 (+119.23%)
Mutual labels:  rollup, rollup-plugin
gulp-boilerplate
Gulp boilerplate
Stars: ✭ 24 (-7.69%)
Mutual labels:  gulp, postcss
web-config
A Rollup configuration to build modern web applications with sweet features as for example SCSS imports, Service Worker generation with Workbox, Karma testing, live reloading, coping resources, chunking, treeshaking, Typescript, license extraction, filesize visualizer, JSON import, budgets, build progress, minifying and compression with brotli a…
Stars: ✭ 17 (-34.62%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-markdown
import JavaScript from Markdown code blocks
Stars: ✭ 16 (-38.46%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-generate-html-template
Rollup plugin for automatically injecting a script tag with the final bundle into an html file.
Stars: ✭ 58 (+123.08%)
Mutual labels:  rollup, rollup-plugin
gulp-reporter
Error report for: CSSLint/EditorConfig/ESLint/HTMLHint/JSCS/JSHint/PostCSS/Standard/TSLint/XO
Stars: ✭ 17 (-34.62%)
Mutual labels:  gulp, postcss
rollup-plugin-lit-css
Moved to https://github.com/bennypowers/lit-css
Stars: ✭ 35 (+34.62%)
Mutual labels:  rollup, rollup-plugin
fly-helper
It's a Tool library, method collection
Stars: ✭ 21 (-19.23%)
Mutual labels:  gulp, rollup

PostCSS Font Grabber

Build Status Downloads Build status Coverage Status License

A postcss plugin, it grabs remote font files and update your CSS, just like that.

postcss-font-grabber v3.x only works with postcss v8,for postcss v7, please take a look at the v2.x branch.

Motivation

You may not want to use remote fonts, because:

  • It may expose your internal project
  • Font services could be unstable sometimes
  • You can do more things with local font files
  • GDPR compliance

Features

  • Standalone without any dependency
  • Written in TypeScript
  • Infer font file extension from HTTP response header (Thanks to @FTWinston)
  • Support custom download function (the download option)

Installation

Requires: Node >= 10.0, postcss 8.*

npm install postcss postcss-font-grabber --save-dev

Usages

With Gulp

gulp.task('css', () => {
  const postcss = require('gulp-postcss');
  const { postcssFontGrabber } = require('postcss-font-grabber');

  return gulp
    .src('src/css/**/*.css')
    .pipe(
      postcss([
        postcssFontGrabber({
          // postcss-font-grabber needs to know the CSS output
          // directory in order to calculate the new font URL.
          cssDest: 'dist/',
          fontDest: 'dist/fonts/',
        }),
      ]),
    )
    .pipe(gulp.dest('dist/'));
});

With Rollup

This example is using Rollup 2 with:

rollup.config.js:

import postcss from 'rollup-plugin-postcss';

export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs',
  },
  plugins: [
    postcss({
      plugins: [
        postcssFontGrabber({
          // postcss-font-grabber needs to know the CSS output
          // directory in order to calculate the new font URL.
          cssDest: 'dist/',
          fontDest: 'dist/fonts/',
        }),
      ],
    }),
  ],
};

With Webpack

This example is using Webpack 5 with:

webpack.config.js:

import path from 'path';

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader', 'postcss-loader'],
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        use: ['file-loader'],
      },
    ],
  },
};

postcss.config.js:

import { postcssFontGrabber } from 'postcss-font-grabber';

module.exports = {
  plugins: [
    postcssFontGrabber({
      cssSrc: 'src/css/',
      // When using with `Webpack` you must set `cssDest` as the same as `cssSrc`,
      // since `Webpack` kept updated CSS files in memory, your source files will
      // be fine.
      // When `PostCSS` is done its job, `Webpack` then use `file-loader` to
      // embedding font file references into the dist file.
      cssDest: 'src/css/',
      fontDest: 'tmp/css/fonts/',
    }),
  ],
};

With Only PostCSS

PostCSS-Font-Grabber will use from and to options of PostCSS setting as the default options of cssSrc (from), cssDest and fontDest (to).

Options

Name Type Default Description
cssSrc string opts.from from PostCSS's setting The root directory path of all CSS files
cssDest string opts.to from PostCSS's setting The directory where the transpiled CSS files are in
fontDest string the same as cssDest The directory where the downloaded fonts stored
download (fontSpec: FontSpec) => Promise<{ data: Readable, mimeType?: string }> - Custom function to download font files. Maybe you want to customize UserAgent or something?

TypeScript

You can import types if you need to (only in TypeScript):

import { FontSpec, Downloader, DownloadResult } from 'postcss-font-grabber';

License

Licensed under the APACHE LISENCE 2.0.

Credits

PostCSS

PostCSS Copy Assets

Issue Reporters

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].