3-webpack4.x打包多页面应用

2019-01-28  本文已影响0人  崩鲨卡拉卡

先上图看下config.js的配置

多页面应用.png

-1.yarn add html-webpack-plugin 先安装抽离页面到输出的插件。
-2.const HtmlWebpackPlugin=require('html-webpack-plugin'); 在配置文件顶部引入
-3.代码块贴出来,方便c v:

const path=require('path');
const HtmlWebpackPlugin=require('html-webpack-plugin');
module.exports={
    mode:'development',
    entry:{
        home:'./src/index.js',
        other:'./src/other.js'
    },
    output:{
        filename:'[name].js',
        path:path.resolve(__dirname,'dist')
    },
    plugins:[
        new HtmlWebpackPlugin({
            template:'./src/index.html',
            filename:'html/home.html',
            chunks:['home']
        }), new HtmlWebpackPlugin({
            template:'./src/index.html',
            filename:'html/ohter.html',
            chunks:['other']
        })
    ]
}
上一篇 下一篇

猜你喜欢

热点阅读