Skip to content

Commit fd9d255

Browse files
committed
fix(build): fix --dest flag regression
close #1193
1 parent a6e47ce commit fd9d255

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

packages/@vue/cli-service/lib/PluginAPI.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path')
2-
const chalk = require('chalk')
32
const { matchesPluginId } = require('@vue/cli-shared-utils')
43

54
class PluginAPI {
@@ -115,18 +114,7 @@ class PluginAPI {
115114
* @return {object} Raw webpack config.
116115
*/
117116
resolveWebpackConfig (chainableConfig) {
118-
const config = this.service.resolveWebpackConfig(chainableConfig)
119-
// performa a few warning checks
120-
const options = this.service.projectOptions
121-
if (config.output.path !== this.resolve(options.outputDir)) {
122-
console.error(chalk.red(
123-
`\n\nConfiguration Error: ` +
124-
`Avoid modifying webpack output.path directly. ` +
125-
`Use the "outputDir" option instead.\n`
126-
))
127-
process.exit(1)
128-
}
129-
return config
117+
return this.service.resolveWebpackConfig(chainableConfig)
130118
}
131119

132120
/**

packages/@vue/cli-service/lib/commands/build/index.js

+47-17
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,14 @@ module.exports = (api, options) => {
5656
}
5757
}
5858

59-
// respect inline build destination
59+
const targetDir = api.resolve(args.dest || options.outputDir)
60+
61+
// respect inline build destination in copy plugin
6062
if (args.dest) {
61-
const dest = path.resolve(
62-
api.service.context,
63-
args.dest
64-
)
6563
api.chainWebpack(config => {
66-
config.output.path(dest)
6764
if (args.target === 'app') {
6865
config.plugin('copy').tap(args => {
69-
args[0][0].to = dest
66+
args[0][0].to = targetDir
7067
return args
7168
})
7269
}
@@ -86,16 +83,45 @@ module.exports = (api, options) => {
8683
webpackConfig = api.resolveWebpackConfig()
8784
}
8885

89-
// get final output directory from resolve raw config
90-
// because the user may have manually overwritten it too
91-
const config = Array.isArray(webpackConfig)
92-
? webpackConfig[0]
93-
: webpackConfig
94-
const targetDir = config.output.path
95-
const targetDirShort = path.relative(
96-
api.service.context,
97-
targetDir
98-
)
86+
// apply inline dest path after user configureWebpack hooks
87+
// so it takes higher priority
88+
if (args.dest) {
89+
const applyDest = config => {
90+
config.output.path = targetDir
91+
}
92+
if (Array.isArray(webpackConfig)) {
93+
webpackConfig.forEach(applyDest)
94+
} else {
95+
applyDest(webpackConfig)
96+
}
97+
}
98+
99+
// grab the actual output path and check for common mis-configuration
100+
const actualTargetDir = (
101+
Array.isArray(webpackConfig)
102+
? webpackConfig[0]
103+
: webpackConfig
104+
).output.path
105+
106+
if (!args.dest && actualTargetDir !== api.resolve(options.outputDir)) {
107+
// user directly modifys output.path in configureWebpack or chainWebpack.
108+
// this is not supported because there's no way for us to give copy
109+
// plugin the correct value this way.
110+
console.error(chalk.red(
111+
`\n\nConfiguration Error: ` +
112+
`Avoid modifying webpack output.path directly. ` +
113+
`Use the "outputDir" option instead.\n`
114+
))
115+
process.exit(1)
116+
}
117+
118+
if (actualTargetDir === api.service.context) {
119+
console.error(chalk.red(
120+
`\n\nConfiguration Error: ` +
121+
`Do not set output directory to project root.\n`
122+
))
123+
process.exit(1)
124+
}
99125

100126
return new Promise((resolve, reject) => {
101127
rimraf(targetDir, err => {
@@ -114,6 +140,10 @@ module.exports = (api, options) => {
114140
}
115141

116142
if (!args.silent) {
143+
const targetDirShort = path.relative(
144+
api.service.context,
145+
targetDir
146+
)
117147
log(formatStats(stats, targetDirShort, api))
118148
if (args.target === 'app') {
119149
done(`Build complete. The ${chalk.cyan(targetDirShort)} directory is ready to be deployed.\n`)

0 commit comments

Comments
 (0)