-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (36 loc) · 1.07 KB
/
Copy pathindex.js
File metadata and controls
48 lines (36 loc) · 1.07 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
// @ts-check
const path = require('path')
const deepMerge = require('deepmerge')
const semver = require('semver')
/**
* @param {object} config
* @param {string} env
* @param {object} htmlWebpackPluginOptions
*/
function rewireHtmlWebpackPlugin(config, env, htmlWebpackPluginOptions = {}) {
const optionKey = htmlWebpackPluginOptionKey()
const htmlWebpackPlugin = config.plugins.find(
plugin => plugin.constructor.name === 'HtmlWebpackPlugin'
)
if (!htmlWebpackPlugin) {
throw new Error("Can't find HtmlWebpackPlugin")
}
htmlWebpackPlugin[optionKey] = deepMerge(
htmlWebpackPlugin[optionKey],
htmlWebpackPluginOptions
)
return config
}
function htmlWebpackPluginOptionKey() {
const version = htmlWebpackPluginVersion()
let optionKey = 'options'
if (semver.major(version) === 5 && semver.lt(version, '5.5.4')) {
optionKey = 'userOptions'
}
return optionKey
}
function htmlWebpackPluginVersion() {
const packageJson = require('html-webpack-plugin/package.json')
return packageJson.version
}
module.exports = rewireHtmlWebpackPlugin