GithubHelp home page GithubHelp logo

font-loader's Introduction

font-loader

Use your fonts in webpack-based projects!

Usage

Add font-loader to your list of CSS loaders.

{
	modules: {
		loaders: [{
			test: /\.css$/,
			loaders: [
				'style',
				'css?importLoaders=1',
				'font?format[]=truetype&format[]=woff&format[]=embedded-opentype'
			]
		}]
	}
}

Create a font manifest file which describes the variants in the font and includes paths to their TTF/OTF/WOFF/etc. files. Variant metadata matches what is found in CSS (e.g. weight and style).

{
	"name": "Proxima Nova",
	"files": [{
		"weight": 100,
		"file": "./files/Proxima Nova Thin.otf"
	}, {
		"weight": 300,
		"file": "./files/Proxima Nova Light.otf"
	}, {
		"weight": 400,
		"file": "./files/Proxima Nova Reg.otf"
	}, {
		"weight": 500,
		"file": "./files/Proxima Nova Sbold.otf"
	}, {
		"weight": 700,
		"file": "./files/Proxima Nova Bold.otf"
	}, {
		"weight": 900,
		"file": "./files/Proxima Nova Xbold.otf"
	}]
}

Create a package.json that points to your new font.

{
	"name": "font-myfont",
	"main": "myfont.font.json"
}

Use your font in CSS.

@import "~font-myfont";

Control which variants are included.

@import "~font-myfont?weight[]=100&weight[]=500&format=woff";

Use your font in JavaScript.

var myfont = require('font-myfont');
console.log(myfont); // { name: "Proxima Nova", files: [...] }

Example

npm link
cd example
npm install
npm link font-loader
webpack

Configuration

Some stuff.

Thoughts:

  • Investigate if it's better to emit a single CSS file containing the font, and then have the loader resolve that as an "import" directive?
  • Fix assorted hackiness
  • WOFF2 support

font-loader's People

Contributors

izaakschroeder avatar kevinrademan avatar natchiketa avatar sisheogorath avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.