react-native-font-loader

1.0.0 • Public • Published

react-native-font-loader

npm versionBuild Status

Import and use fonts easily in your react-native app

Usage

  • Install
    # file-loader is peerDependency 
    npm install --save-dev react-native-font-loader file-loader
    # or yarn 
    yarn add -D react-native-font-loader file-loader
  • Add loader to your webpack-config
    ...
     module: {
        rules: [
          {
              test: /\.ttf$/,
              use: [
                {
                  loader: 'react-native-font-loader',
                  options: {
                    path: './assets/',
                  },
                },
              ]
          }
        ]
     }
  • Import ttfs and use them in your code!
    import React, { Component } from 'react';
    import { View, Text, StyleSheet } from 'react-native';
    import someFontFamily from 'some.ttf';
     
    const stylesheet = StyleSheet.create({
      welcomeText: {
        fontFamily: someFontFamily,
        fontSize: 24,
      },
    });
     
    export default class App extends Component {
      render() {
        return (
          <View>
            <Text style={stylesheet.welcomeText}>
              Welcome to my React app!
            </Text>
          </View>
        );
      }
    }

Package Sidebar

Install

npm i react-native-font-loader

Weekly Downloads

9

Version

1.0.0

License

ISC

Last publish

Collaborators

  • unimonkiez