GithubHelp home page GithubHelp logo

geoctrl / webpack-roboto Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 2.88 MB

Embed the Roboto font into your application with Webpack (using Sass)

License: MIT License

CSS 51.54% JavaScript 35.20% HTML 13.27%

webpack-roboto's Introduction

webpack-roboto

Embed the Roboto font into your application with Webpack

Set Up

This is a pretty specific setup, but I'm sure you can do it with other commonJS module loaders. You'll need the following NPM modules installed (not including all the other stuff you'll need for sass, etc):

  • file-loader
  • resolve-url-loader

In your webpack.config.js, you'll need to add in resolve-url-loader to your sass loader and you'll need the file-loader added to be able to handle font embedding.

config.loaders = [
  {
    test: /\.scss$/,
    loader: 'style!css!resolve-url!postcss-loader!sass',
    exclude: /node_modules/
  },
  {
    test: /\.(ttf|woff|woff2)$/,
    loader: 'file?name=fonts/[name].[ext]',
    exclude: /node_modules/
  }
}

Usage

Import (or require) the module and then call embed()

import roboto from 'webpack-roboto';
roboto.embed();

This will add all Roboto fonts. If you want only a specific set of fonts, pass in an array following the ${weight}-${style} syntax:

roboto.embed([
  '400-normal',
  '400-italic',
  '700-normal'
]);

For each import, webpack adds a new <style> tag in the header with all the required css.

Roadmap

I'd like to make this more modular so Roboto isn't the only font available. Much like how BabelJS has a modular preset system, we can make this project font agnostic, then include fonts that you would want as different packages.

webpack-roboto's People

Contributors

geoctrl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

webpack-roboto's Issues

Import not works

It does not work

import roboto from 'webpack-roboto';
roboto.embed();

But if use require, everything gonna be alright:

let roboto = require('webpack-roboto');
roboto.embed();

Hope you still support this project, thank you!

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.