下载阿里的字体图标库文件,放在\src\assets\font文件夹下面。
安装style-loader,css-loader和file-loader (或url-loader) ,记得–save-dev
webpack的配置文件中添加:
{ test: /\.css$/, use:['style-loader','css-loader'] }, { test:/\.(ttf|eot|woff|woff2|svg)$/, use:['file-loader'] }
入口文件main.js引入
import './assets/font/iconfont.css';
如果已经安装了插件,webpack配置文件里面也添加,还是报以下错误:
Unexpected character '@' (2:0) You may need an appropriate loader to handle this file type. @font-face {font-family: "iconfont"; src: url('iconfont.eot?t=1529419541319'); /* IE9*/ src: url('iconfont.eot?t=1529419541319#iefix') format('embedded-opentype'), /* IE6-IE8 */
建议检查仔细webpack配置文件是否有错误,比如逗号,括号等是否漏写。
然后重新运行项目npm run dev。
如果还是报错,试试将iconfont.css文件中的路径修改下,然后重新运行项目。
@font-face {font-family: "iconfont"; src: url('./iconfont.eot?t=1529419541319'); /* IE9*/ src: url('./iconfont.eot?t=1529419541319#iefix')
转载于:https://www.cnblogs.com/qiu-freedom/p/10348634.html