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
        })
}

猜你喜欢

转载自blog.csdn.net/qq_44242707/article/details/127570507
今日推荐