vue-cli5升级:Multiple assets emit different content to the same filename index.html编译报错

  1. 背景:升级vue-cli5 + 使用copy-plugin插件
  2. 报错信息:Multiple assets emit different content to the same filename index.html
  3. 关键代码:
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
        })
}
  1. 问题:生成重复的index.html文件,在copy-plugin的参数修改中没有过滤掉index.html导致重复拷贝
  2. 解决:修改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
        })
}

你可能感兴趣的:(升级,webpack5,+,vue-cli5,vue.js,前端,javascript,webpack)