vue-cli如何打包和圖片上傳丟失問題
阿新 • • 發佈:2018-12-12
vue專案的打包
需要修改config/index.js裡的assetsPublicPath的欄位,初始專案是/他是指向專案根目錄的也是為什麼會出現錯誤,這時改為./
如下:
build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: './', //加上一個 . 改變路徑 /** * Source Maps */ productionSourceMap: true, // https://webpack.js.org/configuration/devtool/#production devtool: '#source-map', // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report }
然後在命名行裡輸出npm run build進行打包,這時你的專案下會出現dist資料夾,複製出來上傳伺服器
解決vue-cli打包時背景圖片丟失問題
需要更改build/utils.js的配置,如下
if (options.extract) { return ExtractTextPlugin.extract({ publicPath:'../../', use: loaders, fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) }
以上就是這篇文章的全部內容