|
1 | 1 | const assert = require('assert'); |
2 | 2 | const child = require('./compiler'); |
3 | 3 | const Oracle = require('./oracle'); |
4 | | -const {tap} = require('./compat'); |
| 4 | +const {tap, tapHtml} = require('./compat'); |
5 | 5 |
|
6 | 6 | module.exports = class WebappWebpackPlugin { |
7 | 7 | constructor(args) { |
@@ -40,15 +40,14 @@ module.exports = class WebappWebpackPlugin { |
40 | 40 | tap(compiler, 'make', 'WebappWebpackPlugin', (compilation, callback) => |
41 | 41 | // Generate favicons |
42 | 42 | child.run(this.options, compiler.context, compilation) |
43 | | - .then(result => { |
| 43 | + .then(tags => { |
44 | 44 | if (this.options.inject) { |
45 | 45 | // Hook into the html-webpack-plugin processing and add the html |
46 | | - tap(compilation, 'html-webpack-plugin-before-html-processing', 'WebappWebpackPlugin', (htmlPluginData, callback) => { |
47 | | - const htmlPluginDataInject = htmlPluginData.plugin.options.inject && htmlPluginData.plugin.options.favicons !== false; |
| 46 | + tapHtml(compilation, 'WebappWebpackPlugin', (htmlPluginData, callback) => { |
| 47 | + const htmlPluginDataInject = htmlPluginData.plugin.options.inject && htmlPluginData.plugin.options.favicons !== false; |
48 | 48 | if ( htmlPluginDataInject || this.options.inject === 'force') { |
49 | | - let position = htmlPluginData.html.search(/<\/head>/i); |
50 | | - position = position === -1 ? htmlPluginData.html.length : position; |
51 | | - htmlPluginData.html = [htmlPluginData.html.slice(0, position), result, htmlPluginData.html.slice(position)].join(''); |
| 49 | + const idx = (htmlPluginData.html + '</head>').search(/<\/head>/i); |
| 50 | + htmlPluginData.html = [htmlPluginData.html.slice(0, idx), ...tags, htmlPluginData.html.slice(idx)].join(''); |
52 | 51 | } |
53 | 52 | return callback(null, htmlPluginData); |
54 | 53 | }); |
|
0 commit comments