12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 'use strict';
- const escapeStringRegexp = require('escape-string-regexp');
- class InterpolateHtmlPlugin {
- constructor(htmlWebpackPlugin, replacements) {
- this.htmlWebpackPlugin = htmlWebpackPlugin;
- this.replacements = replacements;
- }
- apply(compiler) {
- compiler.hooks.compilation.tap('InterpolateHtmlPlugin', compilation => {
- this.htmlWebpackPlugin
- .getHooks(compilation)
- .afterTemplateExecution.tap('InterpolateHtmlPlugin', data => {
-
- Object.keys(this.replacements).forEach(key => {
- const value = this.replacements[key];
- data.html = data.html.replace(
- new RegExp('%' + escapeStringRegexp(key) + '%', 'g'),
- value
- );
- });
- });
- });
- }
- }
- module.exports = InterpolateHtmlPlugin;
|