Skip to content

Instantly share code, notes, and snippets.

@hoangmirs
Last active November 24, 2018 04:17
Show Gist options
  • Save hoangmirs/798d3344f63864515f5a7bc8b62db4f7 to your computer and use it in GitHub Desktop.
Save hoangmirs/798d3344f63864515f5a7bc8b62db4f7 to your computer and use it in GitHub Desktop.
Config build multiple environment for vuejs with webpack
// build/build.js
// Replace
process.env.NODE_ENV = 'production'
// with
process.env.NODE_ENV = process.argv[2] || 'production'
// Replace
const spinner = ora('building for production...')
// with
const spinner = ora(`building for ${process.env.NODE_ENV}...`)
const production = {
user: 'deploy',
host: '192.168.1.10',
ref: 'origin/master',
repo: '[email protected]:hoangmirs/hoang_app.git',
path: '/home/deploy/hoang_app',
fetch: '--all',
'post-deploy': 'yarn install && yarn build production',
};
module.exports = {
apps: [{
name: 'hoang_app',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
}],
deploy: {
dev: {
...production,
ref: 'origin/develop',
path: '/home/deploy/hoang_app_dev',
'post-deploy': 'yarn install && yarn build dev',
},
staging: {
...production,
ref: 'origin/staging',
path: '/home/deploy/hoang_app_staging',
'post-deploy': 'yarn install && yarn build staging',
},
production: { ...production }
}
};
// config/staging.env.js
'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"staging"',
})
// build/webpack.prod.conf.js
// Replace
const env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
: require('../config/prod.env')
// with
const configPaths = {
test: '../config/test.env',
dev: '../config/dev.env',
staging: '../config/staging.env',
production: '../config/prod.env',
};
const env = require(configPaths[process.env.NODE_ENV]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment