You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow different policies on individual HtmlWebpackPlugin instances (#26)
* renaming disableCspPlugin to cspPlugin.enabled to be more inline with the main enabled setting
* Adding the option to allow individual policies on a specific html webpack plugin instance
* Updating README to reflect the new changes
Copy file name to clipboardExpand all lines: README.md
+28-2Lines changed: 28 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,10 +40,24 @@ This `CspHtmlWebpackPlugin` accepts 2 params with the following structure:
40
40
*`{object}` Policy (optional) - a flat object which defines your CSP policy. Valid keys and values can be found on the [MDN CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) page. Values can either be a string or an array of strings.
41
41
*`{object}` Additional Options (optional) - a flat object with the optional configuration options:
42
42
*`{boolean}` devAllowUnsafe - if you as the developer want to allow `unsafe-inline`/`unsafe-eval` and _not_ include hashes for inline scripts. If any hashes are included in the policy, modern browsers ignore the `unsafe-inline` rule.
43
-
*`{boolean|Function}` enabled - if false, or the function returns false, the empty CSP tag will be stripped from the html output. The `htmlPluginData` is passed into the function as it's first param.
43
+
*`{boolean|Function}` enabled - if false, or the function returns false, the empty CSP tag will be stripped from the html output.
44
+
* The `htmlPluginData` is passed into the function as it's first param.
45
+
* If `enabled` is set the false, it will disable generating a CSP for all instances of `HtmlWebpackPlugin` in your webpack config.
44
46
*`{string}` hashingMethod - accepts 'sha256', 'sha384', 'sha512' - your node version must also accept this hashing method.
45
47
46
-
_Note: CSP runs on all files created by HTMLWebpackPlugin. You can disable it for a particular instance by setting `disableCspPlugin` to `true` in the HTMLWebpackPlugin options
48
+
The plugin also adds a new config option onto each `HtmlWebpackPlugin` instance:
49
+
*`{object}` cspPlugin - an object containing the following properties:
50
+
*`{boolean}` enabled - if false, the CSP tag will be removed from the HTML which this HtmlWebpackPlugin instance is generating.
51
+
*`{object}` policy - A custom policy which should be applied only to this instance of the HtmlWebpackPlugin
52
+
53
+
Note that policies are merged in the following order:
54
+
```
55
+
> HtmlWebpackPlugin cspPlugin.policy
56
+
> CspHtmlWebpackPlugin policy
57
+
> CspHtmlWebpackPlugin defaultPolicy
58
+
```
59
+
60
+
If 2 policies have the same key/policy rule, the former policy will override the latter policy. Entries in a specific rule will not be merged; they will be replaced.
47
61
48
62
#### Default Policy:
49
63
@@ -68,6 +82,18 @@ _Note: CSP runs on all files created by HTMLWebpackPlugin. You can disable it fo
it('merges and overwrites policies, with a html webpack plugin instance policy taking precedence, followed by the csp instance, and then the default policy',done=>{
0 commit comments