vue项目打包后字体文件路径出错的解决办法

打包后,css里加载的font文件路径变成了:rootpath/static/css/static/fonts,
而期望的应该是rootpath/static/fonts。
修改方式:在build/utils的ExtractTextPlugin.extract里加上 publicPath: '../../':

// generate loader string to be used with extract text plugin
  function generateLoaders (loader, loaderOptions) {
    const loaders = [cssLoader]
    if (loader) {
      loaders.push({
        loader: loader + '-loader',
        options: Object.assign({}, loaderOptions, {
          sourceMap: options.sourceMap
        })
      })
    }

    // Extract CSS when that option is specified
    // (which is the case during production build)
    if (options.extract) {
      return ExtractTextPlugin.extract({
        use: loaders,
        fallback: 'vue-style-loader',
        publicPath: '../../'  //加这里
      })
    } else {
      return ['vue-style-loader'].concat(loaders)
    }
  }

 

你可能感兴趣的:(Vue)