-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support Trusted Types for client overlay
- Loading branch information
Showing
12 changed files
with
522 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# client.overlay.policyName option | ||
|
||
**webpack.config.js** | ||
|
||
```js | ||
module.exports = { | ||
// ... | ||
output: { | ||
trustedTypes: { policyName: "webpack" }, | ||
}, | ||
devServer: { | ||
client: { | ||
overlay: { | ||
policyName: "overlay-policy", | ||
}, | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
Usage via CLI: | ||
|
||
```shell | ||
npx webpack serve --open | ||
``` | ||
|
||
## What Should Happen | ||
|
||
1. The script should open `http://localhost:8080/` in your default browser. | ||
2. You should see an overlay in browser for compilation errors. | ||
3. Modify `devServer.client.overlay.policyName` in webpack.config.js to `disallowed-policy` and save. | ||
4. Restart the command and you should not see an overlay at all. In the console you should see the following error: | ||
|
||
``` | ||
Refused to create a TrustedTypePolicy named 'disallowed-policy' because it violates the following Content Security Policy directive: "trusted-types webpack overlay-policy". | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
const target = document.querySelector("#target"); | ||
|
||
target.classList.add("pass"); | ||
target.textContent = "Success!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!-- Originally copied from "../../.assets/layout.html" --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- Enable Trusted Types --> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content="require-trusted-types-for 'script'; trusted-types webpack overlay-policy;" | ||
/> | ||
|
||
<title>WDS ▻ <%= htmlWebpackPlugin.options.title %></title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="shortcut icon" href=".assets/favicon.ico" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://fonts.googleapis.com/css?family=Source+Code+Pro:400,600|Source+Sans+Pro:400,400i,500,600" | ||
/> | ||
<link rel="stylesheet" href=".assets/style.css" /> | ||
</head> | ||
<body> | ||
<main> | ||
<header> | ||
<h1> | ||
<img | ||
src=".assets/icon-square.svg" | ||
style="width: 35px; height: 35px" | ||
/> | ||
webpack-dev-server | ||
</h1> | ||
</header> | ||
<section> | ||
<h2><%= htmlWebpackPlugin.options.title %></h2> | ||
<div id="target"></div> | ||
</section> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
// our setup function adds behind-the-scenes bits to the config that all of our | ||
// examples need | ||
const { setup } = require("../../util"); | ||
|
||
const config = setup({ | ||
context: __dirname, | ||
// create error for overlay | ||
entry: "./invalid.js", | ||
output: { | ||
trustedTypes: { policyName: "webpack" }, | ||
}, | ||
devServer: { | ||
client: { | ||
overlay: { | ||
policyName: "overlay-policy", | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// overwrite the index.html with our own to enable Trusted Types | ||
config.plugins[0] = new HtmlWebpackPlugin({ | ||
filename: "index.html", | ||
template: path.join(__dirname, "./layout.html"), | ||
title: "trusted types overlay", | ||
}); | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.