webpack icon indicating copy to clipboard operation
webpack copied to clipboard

Can`t use prod.env.js variable in proxy config

Open aaburkov opened this issue 3 years ago • 0 comments

prod.env.js

'use strict'
module.exports = {
  NODE_ENV: '"production"',
  ROOT_API: '"/api"'
}

config/index.js

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
const port = 3000 
const apiPort = 4000

module.exports = {
  dev: {
    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      [process.env.ROOT_API]: {
        target: `http://127.0.0.1:${apiPort}/`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.ROOT_API]: ''
        }
      }
    },
...

And after build config in proxy object i get

undefined: {
        target: `http://127.0.0.1:4000/`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + undefined ]: ''
        }
      }

How i can use env variables in config files?

aaburkov avatar Aug 07 '20 08:08 aaburkov