Last active
November 24, 2018 04:17
-
-
Save hoangmirs/798d3344f63864515f5a7bc8b62db4f7 to your computer and use it in GitHub Desktop.
Config build multiple environment for vuejs with webpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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}...`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/staging.env.js | |
'use strict' | |
const merge = require('webpack-merge') | |
const prodEnv = require('./prod.env') | |
module.exports = merge(prodEnv, { | |
NODE_ENV: '"staging"', | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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