vue打包字體文件路徑錯誤的問題

問題1

轉載自 http://www.itdecent.cn/p/458fe9cb3490

根本原理請看:https://github.com/vuejs-templates/webpack/issues/166

在我的項目中遇到的情形是:
打包后,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)
    }
  }

問題2

更改config/index.js中生產模式下(build)的assetsPublicPth, 原本為 /, 改為 ./ 。

build: {
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',         //改這里
    ....
}

問題3 vue-cli3 的 vue.config.js修改

module.exports = {
  publicPath: '/',
  outputDir: 'dist',
  filenameHashing: true
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容