ERROR in Conflict: Multiple assets emit different content to the same filename index.html

前置期望:多入口起点,多个HTML,每个HTML配置一个入口起点

初始出错的webpack关键配置信息

module.exports = {
  mode: 'development',
  entry: {
    entry1: './src/entry1/index.ts',
    entry2: './src/entry2/index.ts'
  },
  output: {
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
  plugins: [
     new HtmlWebpackPlugin({
        title: 'entry1_HTML_FILE',
        inject: "body",
        template: "./src/entry1_sub_directory/entry1_template.html",
        chunks: ['entry1']
     }),
     new HtmlWebpackPlugin({
        title: 'entry2_HTML_FILE',
        inject: "body",
        template: "./src/entry2_sub_directory/entry2_template.html",
        chunks: ['entry2']
     })
  ],
   // BLOG Author: 埃里克森枫
   // ...其他webpack配置信息省略
}

执行打包命令后得到错误信息

ERROR in Conflict: Multiple assets emit different content to the same filename index.html

出错点是插件Html Webpack Plugin 使用了默认的filename(index.html)导致的

因此指定filename就能解决

参考官方文档修改filename

https://github.com/jantimon/html-webpack-plugin#options

filename{String|Function}'index.html'

The file to write the HTML to. Defaults to index.html. You can specify a subdirectory here too (eg: assets/admin.html). The [name] placeholder will be replaced with the entry name. Can also be a function e.g. (entryName) => entryName + '.html'.

 修改后的webpack 配置文件:

module.exports = {
  mode: 'development',
  entry: {
    entry1: './src/entry1/index.ts',
    entry2: './src/entry2/index.ts'
  },
  output: {
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
  plugins: [
     new HtmlWebpackPlugin({
        title: 'entry1_HTML_FILE',
        inject: "body",
        filename: 'entry1.html', // 此处新增
        template: "./src/entry1_sub_directory/entry1_template.html",
        chunks: ['entry1']
     }),
     new HtmlWebpackPlugin({
        title: 'entry2_HTML_FILE',
        inject: "body",
        filename: 'entry2.html', // 此处新增
        template: "./src/entry2_sub_directory/entry2_template.html",
        chunks: ['entry2']
     })
  ],
   // BLOG Author: 埃里克森枫
   // ...其他webpack配置信息省略
}

 

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值