- 背景:升级vue-cli5 + 使用copy-plugin插件
- 报错信息:
Multiple assets emit different content to the same filename index.html
- 关键代码:
chainWebpack: (config) => {
config.plugin('copy').tap(options => {
if (options[0] && options[0].patterns && options[0].patterns[0]) {
const copyOption = JSON.parse(JSON.stringify(options[0].patterns[0]))
copyOption.from = path.resolve(__dirname, 'XtionWebEngine', 'public')
options[0].patterns.unshift(copyOption)
}
return options
})
}
- 问题:生成重复的index.html文件,在copy-plugin的参数修改中没有过滤掉index.html导致重复拷贝
- 解决:修改ignore参数过滤index.html文件
chainWebpack: (config) => {
config.plugin('copy').tap(options => {
if (options[0] && options[0].patterns && options[0].patterns[0]) {
const copyOption = JSON.parse(JSON.stringify(options[0].patterns[0]))
copyOption.from = path.resolve(__dirname, 'XtionWebEngine', 'public')
copyOption.globOptions.ignore = [
'**/.DS_Store',
path.resolve(__dirname, 'XtionWebEngine', 'public', 'index.html').replace(/\\/g, '/')
]
options[0].patterns.unshift(copyOption)
}
return options
})
}