Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Including custom fonts via webpack #87

Open
harrylincoln opened this issue Feb 8, 2017 · 3 comments
Open

Including custom fonts via webpack #87

harrylincoln opened this issue Feb 8, 2017 · 3 comments

Comments

@harrylincoln
Copy link

harrylincoln commented Feb 8, 2017

Has anyone been able to bundle custom fonts with this?

I'm struggling to get my custom fonts served up in the .tmp folder, and eventually the dist, also.

webpack.conf.js

 const webpack = require('webpack');
const conf = require('./gulp.conf');
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');

module.exports = {
  module: {
    preLoaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'eslint'
      }
    ],

    loaders: [
      {
        test: /.json$/,
        loaders: [
          'json'
        ]
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|jpeg|jpg|svg)$/,
        loader: 'url-loader'
      },
      {
        test: /\.(css|scss)$/,
        loaders: [
          'style',
          'css',
          'sass?sourceMap',
          'postcss?sourceMap'
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: [
          'ng-annotate'
        ]
      },
      {
        test: /.html$/,
        loaders: [
          'html'
        ]
      }
    ]
  },
  resolve: {
    alias: {
      'video.js': 'video.js/dist/alt/video.novtt'
    }
  },
  plugins: [
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.NoErrorsPlugin(),
    new HtmlWebpackPlugin({
      template: conf.path.src('index.html')
    })
  ],
  postcss: () => [autoprefixer],
  debug: true,
  devtool: 'source-map',
  output: {
    path: path.join(process.cwd(), conf.paths.tmp),
    filename: 'index.js',
    publicPath: '/'
  },
  entry: `./${conf.path.src('index')}`
};

_typography.scss

@font-face {
  font-family: 'Betty-headings';
  src: url('./app/assets/fonts/MuseoSlab-500.eot?#iefix') format('embedded-opentype'),  url('./app/assets/fonts/MuseoSlab-500.otf')  format('opentype'),
       url('./app/assets/fonts/MuseoSlab-500.woff') format('woff'), url('./app/assets/fonts/MuseoSlab-500.ttf')  format('truetype'), url('./app/assets/fonts/MuseoSlab-500.svg#MuseoSlab-500') format('svg');
  font-weight: normal;
  font-style: normal;
}

Directory architecture:
package.json
conf/
^--webpack.conf.js
dist/
gulp_tasks/
gulpfile.js
src/
^--app/
^---assets/
^----fonts/
^-----MuseoSlab-500.eot

@rafaelescrich
Copy link

rafaelescrich commented Sep 26, 2017

Hi there, I'm having the same problem and already tried a lot of things and nothing happens.

Did you resolved this issue by yourself?

@harrylincoln
Copy link
Author

harrylincoln commented Sep 26, 2017

@rafaelescrich So I remember it was something like this:

  1. you need to specify rules for webpack to understand how to treat specific files(font files in this case) and slam them into a folder ready to query when referencing them in the actual sass/css.
...
{
   test: /\.(eot|svg|ttf|woff|woff2)$/,
   loader: 'file-loader?name=/fonts/[name].[ext]'
},
...
  1. Then in your sass try referencing said files served by webpack like this:
    require('./fonts/font-darkenstone/darkenstone.scss');
    Or something like this? maybe a .././fonts/ etc
    Webpack paths can be tedious but once you get them it kinda makes sense.

More reading here:
https://stackoverflow.com/questions/41335456/using-local-web-fonts-with-webpack

Hope that helps!

@rafaelescrich
Copy link

Thank you very much for your reply.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants