Skip to content

Commit f560e4b

Browse files
committed
fix: avoid copy-webpack plugin errors in modern mode
By adding a placeholder plugin with the same name and options as copy-webpack-plugin. Fixes vuejs#6648 Addresses the concern raised by @tomica at vuejs@cd78376#commitcomment-52141775
1 parent 18c1e8b commit f560e4b

File tree

1 file changed

+21
-14
lines changed
  • packages/@vue/cli-service/lib/config

1 file changed

+21
-14
lines changed

packages/@vue/cli-service/lib/config/app.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,27 @@ module.exports = (api, options) => {
240240

241241
// copy static assets in public/
242242
const publicDir = api.resolve('public')
243-
if (!isLegacyBundle && fs.existsSync(publicDir)) {
244-
webpackConfig
245-
.plugin('copy')
246-
.use(require('copy-webpack-plugin'), [{
247-
patterns: [{
248-
from: publicDir,
249-
to: outputDir,
250-
toType: 'dir',
251-
noErrorOnMissing: true,
252-
globOptions: {
253-
ignore: publicCopyIgnore
254-
}
255-
}]
256-
}])
243+
const CopyWebpackPlugin = require('copy-webpack-plugin')
244+
const PlaceholderPlugin = class PlaceholderPlugin { apply () {} }
245+
246+
const copyOptions = {
247+
patterns: [{
248+
from: publicDir,
249+
to: outputDir,
250+
toType: 'dir',
251+
noErrorOnMissing: true,
252+
globOptions: {
253+
ignore: publicCopyIgnore
254+
}
255+
}]
256+
}
257+
258+
if (fs.existsSync(publicDir)) {
259+
if (isLegacyBundle) {
260+
webpackConfig.plugin('copy').use(PlaceholderPlugin, [copyOptions])
261+
} else {
262+
webpackConfig.plugin('copy').use(CopyWebpackPlugin, [copyOptions])
263+
}
257264
}
258265
})
259266
}

0 commit comments

Comments
 (0)