html-webpack-insert-script-plugin
v2.0.0
Published
a plugin for html-webpack-plugin which can insert code into Html head/footer
Downloads
5
Readme
A plugin for html-webpack-plugin
这是一个html-webpack-plugin的插件,可以在打包的时候插入js代码到html的头部或尾部,可用于增加业务需要的防劫持代码等
##用法
- 需要先使用html-webpack-plugin
- 在html-webpack-plugin后面增加下面代码
var HtmlWebpackInsertPlugin = require('html-webpack-insert-script-plugin'); // 防挟持插入
// 防挟持
new HtmlWebpackInsertPlugin({
open: isProd, //optional 是否打开
head: [
`${__dirname}/src/lib/test/header.js`
],
body: [
`${__dirname}/src/lib/test/footer.js`
]
});
***header.js***
//add Some code hear
var startTime=+new Date();
***footer.js***
//add Some code hear
var endTime=+new Date();
##选项
####open[选配] 是否打开插入的功能,默认开启
####head[选配] 头部所需要插入的js代码文件路径,数组类型,可插入多个
####footer[选配] 底部所需要插入的js代码文件路径,数组类型,可插入多个
##效果
源码html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Cache-Control" content="no-transform">
<meta name="format-detection" content="telephone=no,email=no,adress=no">
<title></title>
</head>
<body>
</body>
</html>
打包后
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Cache-Control" content="no-transform">
<meta name="format-detection" content="telephone=no,email=no,adress=no">
<script type="text/javascript">/**
* Created by zuowenqi on 2018/4/27 0027
*/
//add Some code hear
var startTime=+new Date();
</script></head>
<body>
<script type="text/javascript">/**
* Created by zuowenqi on 2018/4/27 0027
*/
//add Some code hear
var endTime=+new Date();</script></body>
</html>
#更新
- support webpack4 and set open to optional since 1.3.x
- v2.0.0 修正版本号为2.0.0