-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (28 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
// const HtmlWebpackPlugin = require('html-webpack-plugin');
class HtmlWebpackInjectTempalfterEmitPlugin {
constructor(options){
this.options = options
}
apply (compiler) {
// 插件逻辑 调用compilation提供的plugin方法
const sourceStr = this.options.sourceStr
const targetStr = this.options.targetStr
// console.log(this.options,'this.options')
compiler.hooks.compilation.tap('HtmlWebpackInjectTempalfterHtmlPlugin',
(compilation, callback) => {
compilation.plugin(
"html-webpack-plugin-after-html-processing",
function(htmlPluginData, callback) {
// console.log(targetStr,'targetStr')
// console.log(htmlPluginData)
let resultHTML = htmlPluginData.html.replace(sourceStr, targetStr);
// 返回修改后的结果
htmlPluginData.html = resultHTML;
}
);
}
);
}
}
module.exports = HtmlWebpackInjectTempalfterEmitPlugin