账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    新版的vue-cli构建的项目没有dev-server.js如何配置proxyTable
    22
    0

    新版的 vue-cli 构建的项目没有 dev-server.js 如何配置 proxyTable 。
    与之替代的是 webpack.dev.conf.js 配置文件。但是该工程并没有默认依赖插件 http-proxy-middleware
    我尝试使用之前的配置方式,先安装了依赖,然后在 build/index.js 的 dev 中将 proxyTable 做如下配置:

    dev: {
    
        // Paths
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: {
          '/api': {
            target: 'http://api.xxx.com',
            changeOrigin: true,
            pathRewrite: {
              '^/api': ''
            }
          }
        },
    
        // Various Dev Server settings
        host: 'localhost', // can be overwritten by process.env.HOST
        port: 8080, // can be overwritten by process.env.HOST, if port is in use, a free one will be determined
        autoOpenBrowser: false,
        errorOverlay: true,
        notifyOnErrors: true,
        poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
    
        // Use Eslint Loader?
        // If true, your code will be linted during bundling and
        // linting errors and warnings will be shown in the console.
        useEslint: true,
        // If true, eslint errors and warnings will also be shown in the error overlay
        // in the browser.
        showEslintErrorsInOverlay: false,
    
        /**
         * Source Maps
         */
    
        // https://webpack.js.org/configuration/devtool/#development
        devtool: 'eval-source-map',
    
        // If you have problems debugging vue-files in devtools,
        // set this to false - it *may* help
        // https://vue-loader.vuejs.org/en/options.html#cachebusting
        cacheBusting: true,
    
        // 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,
      }

    重新 run 之后发现不起作用,请求地址没有正确转换,仍然是 http://localhost:8080/api/xxx 这样的格式。

    求助一下新版的 vue 脚手架构建的项目如何正确配置 proxyTable 。

    说明:新版的 build 目录中没有 dev-server.jsdev-client.js 这两个文件,也没有默认依赖 http-proxy-middleware 插件。

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 锻己 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部