@@ -56,17 +56,14 @@ module.exports = (api, options) => {
56
56
}
57
57
}
58
58
59
- // respect inline build destination
59
+ const targetDir = api . resolve ( args . dest || options . outputDir )
60
+
61
+ // respect inline build destination in copy plugin
60
62
if ( args . dest ) {
61
- const dest = path . resolve (
62
- api . service . context ,
63
- args . dest
64
- )
65
63
api . chainWebpack ( config => {
66
- config . output . path ( dest )
67
64
if ( args . target === 'app' ) {
68
65
config . plugin ( 'copy' ) . tap ( args => {
69
- args [ 0 ] [ 0 ] . to = dest
66
+ args [ 0 ] [ 0 ] . to = targetDir
70
67
return args
71
68
} )
72
69
}
@@ -86,16 +83,45 @@ module.exports = (api, options) => {
86
83
webpackConfig = api . resolveWebpackConfig ( )
87
84
}
88
85
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
+ }
99
125
100
126
return new Promise ( ( resolve , reject ) => {
101
127
rimraf ( targetDir , err => {
@@ -114,6 +140,10 @@ module.exports = (api, options) => {
114
140
}
115
141
116
142
if ( ! args . silent ) {
143
+ const targetDirShort = path . relative (
144
+ api . service . context ,
145
+ targetDir
146
+ )
117
147
log ( formatStats ( stats , targetDirShort , api ) )
118
148
if ( args . target === 'app' ) {
119
149
done ( `Build complete. The ${ chalk . cyan ( targetDirShort ) } directory is ready to be deployed.\n` )
0 commit comments