Vue.js build with different environment variables

前端 未结 3 650
情歌与酒
情歌与酒 2021-01-31 19:04

I\'ve used official Webpack template for Vue.js. It uses separate configuration for different environments. They offer test, development and production. However, I need another

3条回答
  •  离开以前
    2021-01-31 19:20

    PROD: config/prod.env.js append your VAR='"value"'

    'use strict'
    module.exports = {
      NODE_ENV: '"production"',
      API_URL: '"https://production URL"'
    }
    

    DEV: config/dev.env.js append your VAR='"value"'

    'use strict'
    const merge = require('webpack-merge')
    const prodEnv = require('./prod.env')
    
    module.exports = merge(prodEnv, {
      NODE_ENV: '"development"',
      API_URL: '"http://localhost"'
    })
    

    Your variable will available as process.env.API_URL or process.env.VAR_NAME

提交回复
热议问题