vue+element-ui项目打包, element-icons.woff 和element-icons.ttf 字体文件路径错误,解决方法

先修改 config/index.js文件,将 assetsPublicPath 的 ‘/’ 改为 ‘./’

卸载现有的element-ui,重新安装

npm uninstall element-ui
npm install element-ui

若不行,则继续往下看

由下图可知,通过url-loader将 woff2?|eot|ttf|otf 相关文件打包到 fonts/ 目录下;

vue+element-ui项目打包, element-icons.woff 和element-icons.ttf 字体文件路径错误,解决方法_第1张图片

代码
{
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }

ExtractTextPlugin.extract配置的情况

在 build/utils 文件中的下图所示位置添加 publicPath: ‘…/…/’

vue+element-ui项目打包, element-icons.woff 和element-icons.ttf 字体文件路径错误,解决方法_第2张图片

代码
if (options.extract) {
      return ExtractTextPlugin.extract({
        use: loaders,
        fallback: 'vue-style-loader',
        publicPath: '../../'
      })
    } else {
      return ['vue-style-loader'].concat(loader)
    }

没有ExtractTextPlugin.extract配置的情况

vue+element-ui项目打包, element-icons.woff 和element-icons.ttf 字体文件路径错误,解决方法_第3张图片


if (options.extract) {
      loaders.push({
        loader: MiniCssExtractPlugin.loader,
        options: {
          publicPath: '../../'
        }
      })
    } else {
      loaders.push('vue-style-loader')
    }

你可能感兴趣的:(javascript,vue)