Skip to content

Instantly share code, notes, and snippets.

@bbugh
Created September 26, 2018 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbugh/bcc14a4e9266a5e6578c849b39f35dcd to your computer and use it in GitHub Desktop.
Save bbugh/bcc14a4e9266a5e6578c849b39f35dcd to your computer and use it in GitHub Desktop.
iconfont-webpack-plugin setup on webpack 4
// use with <i class="svg-icon bank-icon"></i>
.svg-icon {
vertical-align: middle; // you may not need this line depending on your icons
}
// borrowed from icomoon's font output
.svg-icon::before {
font-weight: normal;
font-style: normal;
font-variant: normal;
line-height: 1;
speak: none;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
// this is where the magic happens - point this to your svg and all of them will be converted into a font!
.bank-icon::before {
font-icon: url('../../icons/bank.svg');
}
// This is for Vue CLI3's webpack config but it should work fine on any Webpack4 postcss-loader config.
// See the official docs for the basic setup: https://www.npmjs.com/package/iconfont-webpack-plugin#configuration
const merge = require('deepmerge')
const IconfontWebpackPlugin = require('iconfont-webpack-plugin');
module.exports = {
chainWebpack: config => {
config
.module
.rule('scss')
.oneOf('normal')
.use('postcss-loader')
.tap(options => merge(options, {
plugins: (loader) => new IconfontWebpackPlugin(loader)
}))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment