Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: set default NODE_ENV to production when running build command #3859

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/@vue/cli-plugin-e2e-nightwatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ module.exports = (api, options) => {
return runner
})
})

// TODO remove in RC
api.registerCommand('e2e', (args, rawArgv) => {
const { warn } = require('@vue/cli-shared-utils')
warn(`Deprecation Warning: "vue-cli-service e2e" has been renamed to "vue-cli-service test:e2e".`)
return api.service.run('test:e2e', args, rawArgv)
})
}

module.exports.defaultModes = {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-e2e-nightwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"chromedriver": "^2.46.0",
"deepmerge": "^3.2.0",
"execa": "^1.0.0",
"nightwatch": "^0.9.21",
"nightwatch": "^1.0.18",
"selenium-server": "^3.141.59"
}
}
10 changes: 1 addition & 9 deletions packages/@vue/cli-plugin-eslint/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
lint: 'vue-cli-service lint'
},
eslintConfig,
// TODO:
// Move these dependencies to package.json in v4.
// Now in v3 we have to add redundant eslint related dependencies
// in order to keep compatibility with v3.0.x users who defaults to ESlint v4.
devDependencies: {
'babel-eslint': '^10.0.1',
'eslint': '^5.16.0',
'eslint-plugin-vue': '^5.0.0'
}
devDependencies: {}
}

const injectEditorConfig = (config) => {
Expand Down
6 changes: 2 additions & 4 deletions packages/@vue/cli-plugin-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
"dependencies": {
"@vue/cli-shared-utils": "^3.6.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.8.0",
"eslint-loader": "^2.1.2",
"eslint-plugin-vue": "^5.0.0",
"globby": "^9.2.0",
"webpack": ">=4 < 4.29"
},
"optionalDependencies": {
"eslint": "^4.19.1",
"eslint-plugin-vue": "^4.7.1"
}
}
4 changes: 2 additions & 2 deletions packages/@vue/cli-service-global/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@vue/cli-service": "^3.6.0",
"babel-eslint": "^10.0.1",
"chalk": "^2.4.2",
"eslint": "^4.19.1",
"eslint-plugin-vue": "^4.7.1",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"resolve": "^1.10.0",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
Expand Down
27 changes: 17 additions & 10 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = class Service {
}
}

init (mode = process.env.VUE_CLI_MODE) {
init (mode = process.env.VUE_CLI_MODE, command = '') {
if (this.initialized) {
return
}
Expand All @@ -64,10 +64,10 @@ module.exports = class Service {

// load mode .env
if (mode) {
this.loadEnv(mode)
this.loadEnv(mode, command)
}
// load base .env
this.loadEnv()
this.loadEnv(command)

// load user config
const userOptions = this.loadUserOptions()
Expand All @@ -89,7 +89,7 @@ module.exports = class Service {
}
}

loadEnv (mode) {
loadEnv (mode, command) {
const logger = debug('vue:env')
const basePath = path.resolve(this.context, `.env${mode ? `.${mode}` : ``}`)
const localPath = `${basePath}.local`
Expand All @@ -111,18 +111,25 @@ module.exports = class Service {
load(basePath)

// by default, NODE_ENV and BABEL_ENV are set to "development" unless mode
// is production or test. However the value in .env files will take higher
// priority.
// is production or test or running build command.
// However the value in .env files will take higher priority.
if (mode) {
// always set NODE_ENV during tests
// as that is necessary for tests to not be affected by each other
const shouldForceDefaultEnv = (
process.env.VUE_CLI_TEST &&
!process.env.VUE_CLI_TEST_TESTING_ENV
)
const defaultNodeEnv = (mode === 'production' || mode === 'test')
? mode
: 'development'

let defaultNodeEnv
if (mode === 'production' || mode === 'test') {
defaultNodeEnv = mode
} else if (command === 'build') {
defaultNodeEnv = 'production'
} else {
defaultNodeEnv = 'development'
}

if (shouldForceDefaultEnv || process.env.NODE_ENV == null) {
process.env.NODE_ENV = defaultNodeEnv
}
Expand Down Expand Up @@ -203,7 +210,7 @@ module.exports = class Service {
const mode = args.mode || (name === 'build' && args.watch ? 'development' : this.modes[name])

// load env variables, load user config, apply plugins
this.init(mode)
this.init(mode, name)

args._ = args._ || []
let command = this.commands[name]
Expand Down