webpack 浅析-- htmlWebpackPlugin 插件

htmlWebpackPlugin  可以自动的创建 html  文件 动态的引用文件名包含 hash 值得文件

1,使用 npm install html-webpack-plugin --save-dev 安装插件

2,在配置文件中的使用

引用插件

var htmlWebpackPlugin = require('html-webpack-plugin');
插件简单的配置
var htmlWebpackPlugin = require('html-webpack-plugin');
    module.exports = {
        //打包的入口从哪个文件开始
        // 1、可以指定一个入口文件
        //entry:"./src/script/main.js'",
        // 2、可以是一个数组 几个平行的互相依赖的文件打包在一起
        //entry:["./src/script/main.js","./src/script/a.js"],
        // 3、可以是一个对象,多页面下的js文件打包
        entry: {
            main: './src/script/main.js',
            a: './src/script/a.js',
            b: './src/script/b.js',
            c: './src/script/c.js'
        },
        //打包后输出的文件存放地址
        output: {
            path: './dist',//存放路径
            filename: '/js/[name]+[hash].js'//打包后文件名
        },
        //插件
        plugins:[
            new htmlWebpackPlugin({
                // 输出的文件名称 默认index.html 可以带有子目录
                // filename: './dist/index.html',
                filename: './entry/index.html',
                // 源文件
                template: 'index.html',
                // 注入资源
                //inject: true,
                inject:'head',
                title:'hello webpack',
                chunks:['main'],//指定chunks 为 main 的js
            }),
            new htmlWebpackPlugin({
                // 输出的文件名称 默认index.html 可以带有子目录
                // filename: './dist/index.html',
                filename: './entry/a.html',
                // 源文件
                template: 'index.html',
                // 注入资源
                //inject: true,
                inject:'head',
                title:'hello webpack',
                chunks:['a'],//指定chunks 为 a 的js

            }), new htmlWebpackPlugin({
                // 输出的文件名称 默认index.html 可以带有子目录
                // filename: './dist/index.html',
                filename: './entry/b.html',
                // 源文件
                template: 'index.html',
                // 注入资源
                //inject: true,
                inject:'head',
                title:'hello webpack',
                chunks:['b'],

            }), new htmlWebpackPlugin({
                // 输出的文件名称 默认index.html 可以带有子目录
                // filename: './dist/index.html',
                filename: './entry/c.html',
                // 源文件
                template: 'index.html',
                // 注入资源
                //inject: true,
                inject:'head',
                title:'hello webpack',
                chunks:['c'],//指定

            })
        ]
    }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值