Loading in local fonts with webpack 2 and the vue-cli

允我心安 提交于 2019-11-30 14:07:15

I import my fonts this way:

$font_path: '~@/assets/fonts/';

// *********** //
// SOURCE SANS //
// ITALIC
@font-face{
  font-family    : 'Source Sans Pro';
  src            : url($font_path +'SourceSansPro-Italic.eot'); /* IE9 Compat; Modes */
  src            : url($font_path +'SourceSansPro-Italic.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url($font_path +'SourceSansPro-Italic.woff2') format('woff2'), /* Modern Browsers */ url($font_path +'SourceSansPro-Italic.woff') format('woff'); /* Modern Browsers */
  font-style     : italic, oblique;
  font-weight    : 400;
  text-rendering : optimizeLegibility;
}
// REGULAR
@font-face{
  font-family    : 'Source Sans Pro';
  src            : url($font_path +'SourceSansPro-Regular.eot'); /* IE9 Compat; Modes */
  src            : url($font_path +'SourceSansPro-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url($font_path +'SourceSansPro-Regular.woff2') format('woff2'), /* Modern Browsers */ url($font_path +'SourceSansPro-Regular.woff') format('woff'); /* Modern Browsers */
  font-style     : normal;
  font-weight    : 400;
  text-rendering : optimizeLegibility;
}
// SEMI BOLD
@font-face{
  font-family    : 'Source Sans Pro';
  src            : url($font_path +'SourceSansPro-Semibold.eot'); /* IE9 Compat; Modes */
  src            : url($font_path +'SourceSansPro-Semibold.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url($font_path +'SourceSansPro-Semibold.woff2') format('woff2'), /* Modern Browsers */ url($font_path +'SourceSansPro-Semibold.woff') format('woff'); /* Modern Browsers */
  font-style     : normal;
  font-weight    : 600;
  text-rendering : optimizeLegibility;
}
// Use "font-family: $source_sans_pro" in your code.
$source_sans_pro : 'Source Sans Pro', sans-serif;
// [END] SOURCE SANS //
// ***************** //

All my fonts are located in src/assets/fonts/

My webpack.base.conf file contains this loader:

 {
    test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
    loader: 'url-loader',
    options: {
      limit: 10000,
      name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
    }
  },
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!