Skip to content

Commit b5564af

Browse files
committed
fix: respect user configured output path
also ensure wc/lib mode respect user raw webpack config. fix #809
1 parent 0468022 commit b5564af

File tree

6 files changed

+57
-34
lines changed

6 files changed

+57
-34
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ class PluginAPI {
112112
* Resolve the final raw webpack config, that will be passed to webpack.
113113
* Typically, you should call `setMode` before calling this.
114114
*
115+
* @param {ChainableWebpackConfig} [chainableConfig]
115116
* @return {object} Raw webpack config.
116117
*/
117-
resolveWebpackConfig () {
118-
return this.service.resolveWebpackConfig()
118+
resolveWebpackConfig (chainableConfig) {
119+
return this.service.resolveWebpackConfig(chainableConfig)
119120
}
120121

121122
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ module.exports = class Service {
136136
return chainableConfig
137137
}
138138

139-
resolveWebpackConfig () {
139+
resolveWebpackConfig (chainableConfig = this.resolveChainableWebpackConfig()) {
140140
// get raw config
141-
let config = this.resolveChainableWebpackConfig().toConfig()
141+
let config = chainableConfig.toConfig()
142142
// apply raw config fns
143143
this.webpackRawConfigFns.forEach(fn => {
144144
if (typeof fn === 'function') {

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = function formatStats (stats, dir, api) {
22
const fs = require('fs')
3+
const path = require('path')
34
const zlib = require('zlib')
45
const chalk = require('chalk')
56
const ui = require('cliui')({ width: 80 })
@@ -39,7 +40,7 @@ module.exports = function formatStats (stats, dir, api) {
3940
}
4041

4142
function getGzippedSize (asset) {
42-
const filepath = api.resolve(`dist/${asset.name}`)
43+
const filepath = api.resolve(path.join(dir, asset.name))
4344
const buffer = fs.readFileSync(filepath)
4445
return formatSize(zlib.gzipSync(buffer).length)
4546
}
@@ -54,12 +55,12 @@ module.exports = function formatStats (stats, dir, api) {
5455
chalk.cyan.bold(`Size`),
5556
chalk.cyan.bold(`Gzipped`)
5657
) + `\n\n` +
57-
assets.map(a => makeRow(
58-
/js$/.test(a.name)
59-
? chalk.green(`${dir}/${a.name}`)
60-
: chalk.blue(`${dir}/${a.name}`),
61-
formatSize(a.size),
62-
getGzippedSize(a)
58+
assets.map(asset => makeRow(
59+
/js$/.test(asset.name)
60+
? chalk.green(path.join(dir, asset.name))
61+
: chalk.blue(path.join(dir, asset.name)),
62+
formatSize(asset.size),
63+
getGzippedSize(asset)
6364
)).join(`\n`)
6465
)
6566

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

+40-17
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ module.exports = (api, options) => {
2727
args[key] = defaults[key]
2828
}
2929
}
30-
if (args.dest == null) {
31-
args.dest = options.outputDir
32-
}
3330

3431
api.setMode(args.mode)
3532

3633
const fs = require('fs')
34+
const path = require('path')
3735
const chalk = require('chalk')
3836
const rimraf = require('rimraf')
3937
const webpack = require('webpack')
@@ -58,23 +56,48 @@ module.exports = (api, options) => {
5856
}
5957
}
6058

59+
// respect inline build destination
60+
if (args.dest) {
61+
api.configureWebpack({
62+
output: {
63+
path: path.resolve(
64+
api.service.context,
65+
args.dest
66+
)
67+
}
68+
})
69+
}
70+
71+
// resolve raw webpack config
72+
let webpackConfig
73+
if (args.target === 'lib') {
74+
webpackConfig = require('./resolveLibConfig')(api, args, options)
75+
} else if (
76+
args.target === 'wc' ||
77+
args.target === 'wc-async'
78+
) {
79+
webpackConfig = require('./resolveWcConfig')(api, args, options)
80+
} else {
81+
webpackConfig = api.resolveWebpackConfig()
82+
}
83+
84+
// get final output directory from resolve raw config
85+
// because the user may have manually overwritten it too
86+
const config = Array.isArray(webpackConfig)
87+
? webpackConfig[0]
88+
: webpackConfig
89+
const targetDir = config.output.path
90+
const targetDirShort = path.relative(
91+
api.service.context,
92+
targetDir
93+
)
94+
6195
return new Promise((resolve, reject) => {
62-
const targetDir = api.resolve(args.dest)
6396
rimraf(targetDir, err => {
6497
if (err) {
6598
return reject(err)
6699
}
67-
let webpackConfig
68-
if (args.target === 'lib') {
69-
webpackConfig = require('./resolveLibConfig')(api, args, options)
70-
} else if (
71-
args.target === 'wc' ||
72-
args.target === 'wc-async'
73-
) {
74-
webpackConfig = require('./resolveWcConfig')(api, args, options)
75-
} else {
76-
webpackConfig = api.resolveWebpackConfig()
77-
}
100+
78101
webpack(webpackConfig, (err, stats) => {
79102
stopSpinner(false)
80103
if (err) {
@@ -86,9 +109,9 @@ module.exports = (api, options) => {
86109
}
87110

88111
if (!args.silent) {
89-
log(formatStats(stats, options.outputDir, api))
112+
log(formatStats(stats, targetDirShort, api))
90113
if (args.target === 'app') {
91-
done(`Build complete. The ${chalk.cyan(options.outputDir)} directory is ready to be deployed.\n`)
114+
done(`Build complete. The ${chalk.cyan(targetDirShort)} directory is ready to be deployed.\n`)
92115
if (
93116
options.baseUrl === '/' &&
94117
// only log the tips if this is the first build

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path')
22

3-
module.exports = (api, { entry, name, dest }, options) => {
3+
module.exports = (api, { entry, name }, options) => {
44
const libName = (
55
name ||
66
api.service.pkg.name ||
@@ -31,7 +31,6 @@ module.exports = (api, { entry, name, dest }, options) => {
3131
}
3232

3333
config.output
34-
.path(api.resolve(dest))
3534
.filename(`${entryName}.js`)
3635
.chunkFilename(`${entryName}.[id].js`)
3736
.library(libName)
@@ -77,7 +76,7 @@ module.exports = (api, { entry, name, dest }, options) => {
7776
}])
7877
}
7978

80-
return config.toConfig()
79+
return api.resolveWebpackConfig(config)
8180
}
8281

8382
return [

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path')
22
const { resolveEntry, fileToComponentName } = require('./resolveWcEntry')
33

4-
module.exports = (api, { target, entry, name, dest }) => {
4+
module.exports = (api, { target, entry, name }) => {
55
// setting this disables app-only configs
66
process.env.VUE_CLI_TARGET = 'web-component'
77
// Disable CSS extraction and turn on CSS shadow mode for vue-style-loader
@@ -66,7 +66,6 @@ module.exports = (api, { target, entry, name, dest }) => {
6666
}
6767

6868
config.output
69-
.path(api.resolve(dest))
7069
.filename(`${entryName}.js`)
7170
.chunkFilename(`${libName}.[id]${minify ? `.min` : ``}.js`)
7271
// use relative publicPath so this can be deployed anywhere
@@ -109,7 +108,7 @@ module.exports = (api, { target, entry, name, dest }) => {
109108
}])
110109
}
111110

112-
return config.toConfig()
111+
return api.resolveWebpackConfig(config)
113112
}
114113

115114
return [

0 commit comments

Comments
 (0)