vue npm run build 生成的dist部署上去之後居然 發送接口不走代理?原因很簡單

 

正常走代理的請求:(其實http://www.only-screen.xyz:8080/api  ==   http://www.only-screen.xyz:8888)

一般vue 項目這麼打包

npm run build

config/index.js  設置:  之前一個項目我也設置這樣的,部署上去沒問題。

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {
  dev: {
    env: require('./dev.env'),
    host: 'localhost',
    port: 8080,
    autoOpenBrowser: true,
    autoOpenPage: '/login',
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {
        target: 'http://localhost:8888',
        pathRewrite: {
          '^/api': '/'
        }
      }
    },
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  },
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
    productionSourceMap: true,
    // 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
  }
}

效果:   http://www.only-screen.xyz:8080/api  走代理後 等同於訪問: http://www.only-screen.xyz:8888  

生成的dist文件上傳到 linux 、 nginx 正常代理的情況下照理說是沒問題的,

但是我發現前端發送接口,居然 還是按照  8080 發出去,沒有帶 /api 這個 後綴,

找了好久,最後 發現是:

這個文件

箭頭這一行要加上,表示是 base_url  就可以了。  不走代理就這樣解決了。

over

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章