image.png
    目标:webpack打包生成dist文件中格式也这样,各自的html引用各自的js
    首先在webpack.config.js引用:const HtmlWebpackPlugin = require(‘html-webpack-plugin’);
    在webpack.config.js配置多入口和多输入:
    entry: {
    index:’./src/index.js’,
    other:’./src/other.js’,
    another:’./src/another.js’,
    },
    output:{
    filename:”[name].js”,
    path:path.resolve(__dirname,’dist’)
    },
    封装HtmlWebpackPlugin:
    const htmlPlugin = [‘index’,’other’,’another’].map(i=>{
    return new HtmlWebpackPlugin(
    {
    template: ./src/${i}.html,
    filename:${i}.html,
    chunks:[i]
    }
    )
    })
    最后在plugin导入:
    plugins: [
    …htmlPlugin

    ],