webpack4多页应用HTML按需添加入口依赖chunk【html-webpack-plugin & html-inline-entry-chunk-plugin】
在webpack4中使用splitChunkPlugin时,根据需要将公共代码拆分为多个依赖后,需要在创建htmlWebpackPlugin时候按需引入对应入口文件依赖的chunk。但是html-webpack-plugin的chunk配置项只能手动添加,在没有得知拆分后的chunk情况下,无法得知对应html的依赖chunk,也就无法按需做引入。
因此鄙人自己写了个配合html-webpack-plugin的插件,使用方便,效果还行,如果有帮到你,希望能在github上赐我一颗小星星。
github地址:https://github.com/pomelott/html-inline-entry-chunk-plugin
html-inline-entry-chunk-plugin使用教程如下:
单页应用:
// webpack plugin config
module.exports = {
entry: {
index: './src/js/index.js'
},
plugin: [
new inlineHtmlEntryChunkPlugin(),
// when useing inlineHtmlEntryChunkPlugin, the chunk param in htmlWebpackPlugin is invalid
new htmlWebpackPlugin({
entry: 'index',
chunk: ['runtime'] //chunk is invalid
})
]
}
多页应用:
// webpack plugin config
module.exports = {
entry: {
index: './src/js/index.js',
list: './src/js/list.js'
},
plugin: [
new inlineHtmlEntryChunkPlugin(),
new htmlWebpackPlugin({
entry: 'index'
}),
new inlineHtmlEntryChunkPlugin(),
new htmlWebpackPlugin({
entry: 'list'
})
]
}
配置项:
| Name | Type | Default | Description |
|---|---|---|---|
| inject | {Object} | {css: 'head', js: 'body'} | control the assets of position in HTML |
| tag | {Object} | {} | Add additional resource tags |
| tagPriority | {Number} | 0 | Control the insertion order of entry chunk and other tags |
示例:
module.exports = {
plugin: [
new htmlInlineEntryChunkPlugin({
inject: {
js: 'body',
css: 'head'
},
tagPriority: 1,
tag: {
head: [
'https://cdn.bootcdn.net/ajax/libs/basscss/8.1.0/css/basscss-cp.css',
'https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js'
],
body: [
'https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.0/animate.compat.css',
'https://cdn.bootcdn.net/ajax/libs/Chart.js/3.0.0-alpha/Chart.esm.js'
]
}
}),
new htmlWebpackPlugin({
entry: 'index'
})
]
}
webpack4多页应用HTML按需添加入口依赖chunk【html-webpack-plugin & html-inline-entry-chunk-plugin】的更多相关文章
- Word2010中的页眉怎样删除和添加横线
http://jingyan.baidu.com/article/f79b7cb3bb3c629144023e05.html 我们在使用Word2010编辑文档中时,有时需要在页眉下方删除或添加一条横 ...
- 解决:在pom.xml处理添加testng依赖之外,需对testng进行关联
问题描述:当maven项目中下载了testng包,在调用后,执行maven test,未执行testng.xml中指定的测试类. 解决:在pom.xml处理添加testng依赖之外,需对testng进 ...
- 添加Pods依赖
1. 添加所需文件 1.1. 添加 .podspec 文件 1.1.1. 创建 必须文件 使用命令 pod spec create name.podspec 或者直接拷贝一份 1.1.2. 添加内 ...
- 解决“添加远程依赖方式没有效果”的bug
1.添加远程依赖dependencies的compile方式
- 添加 Gradle 依赖与 build.gradle 配置初识
添加 Gradle 我们可以到我们添加 Maven 依赖的网站 Maven Repository: Search/Browse/Explore http://mvnrepository.com/ 上查 ...
- IDEA中添加各种依赖pom.xml文件内容
刚实习的小白,今天准备进入项目,纳尼,前辈把框架什么的都搭建好了,默默的抹了一把辛酸泪,刚刚接触自学框架的时候,添加依赖的时候总是各种问题,让前辈发给我之后,才发现人家写的代码相当优美了.下面就是前辈 ...
- IDEA中Maven管理下添加mysql依赖
在做Java Web项目的时候,不可避免的就要使用到数据库,下面就是在IDEA中添加mysql依赖的方法. 如果你看到这里,就表示你弄懂了IDEA,maven和Tomcat等,所以... 只需要在po ...
- maven添加本地依赖包方法
1.某些情况下不方便上传本地依赖包到Maven repository,可以通过下面方法添加本地依赖包. 2.方法 1).pom.xml中添加以下代码块 <dependency> <g ...
- Maven 手动添加第三方依赖包及编译打包和java命令行编译JAVA文件并使用jar命令打包
一,实例:新建了一个Maven项目,在eclipse中通过 build path –> configure path-.将依赖包添加到工程中后,eclipse不报错了.但是用Maven命令 mv ...
随机推荐
- c++使用cin、cout与c中使用scanf、printf进行输入输出的效率问题
在c++中,我们使用cin和cout进行输入输出会比用scanf和printf更加简洁和方便,但是当程序有大量IO的时候,使用cin和cout进行输入输出会比用scanf和printf更加耗时, 在数 ...
- swoole学习--图文直播和聊天室
其实这个也没有什么好值得记录的,但是前面都记下来了,我也顺便说说吧: 1.为了方便,最好把http服务声明为超全局变量. 2.在一些地方里面,你声明的http超全局变量是用不了的,你只能用他自己内置的 ...
- PHP(ThinkPHP5.0) + PHPMailer 进行邮箱发送验证码
GitHub下载最新版第三方类库PHPMailer: 第一步: 打开网址https://github.com/PHPMailer/PHPMailer/ 下载PHPMailer,PHPMailer 需要 ...
- php正则验证手机、邮箱
//验证电话private function reg_phone($phone){ if (preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189] ...
- 2019-2020-1 20199310《Linux内核原理与分析》第十一周作业
1.问题描述 在一个capability系统中,当一个程序运行时,对应的线程会初始化一系列capabilities(令牌).当线程尝试访问某个对象时,操作系统会检查该线程的capabilities,并 ...
- python学习09元组
'''元组''''''元组Tuple:1.不可变的序列:元祖不能对元素进行变动(字符串也不可以,但是列表可以) 2.元组用小括号()表示(列表是中括号[],字符串是“”) 3.可以存储各种数据类型 4 ...
- SpringBoot系列(十二)过滤器配置详解
SpringBoot(十二)过滤器详解 往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件 ...
- 更改 vsftpd 的端口号
2019独角兽企业重金招聘Python工程师标准>>> vsftpd启动后,默认的ftp端口是21,现在我想把ftp端口改成 801 ,修改后能保证用户上传下载不受影响 1.编辑 / ...
- Prometheus monitor RabbitMQ
Install docker-compose sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2 ...
- 「newbee-mall新蜂商城开源啦」 前后端分离的 Vue 版本即将开源
新蜂商城 Vue 版本 2019 年 10 月份我在 GitHub 开源仓库中上传了新蜂商城项目的所有源码,至今已经有小半年的时间了,感兴趣的可以去了解一下这个 Spring Boot 技术栈开发的商 ...