Skip to content

Commit 3974bcf

Browse files
authored
docs: add non vue webviews documentation (aws#5071)
* docs: add non vue webviews documentation
1 parent 4cda145 commit 3974bcf

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/arch_develop.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,63 @@ Commands and events are defined on the backend via sub-classes of `VueWebview`.
277277
client.init(data => (this.data = data ?? this.data))
278278
```
279279

280+
## Webviews (non Vue)
281+
282+
Some webviews (amazon q chat view, codewhisperer security panel) rely on the native vscode webview implementation using the `vscode.WebviewViewProvider` and the `vscode.window.registerWebviewViewProvider(viewType, panel)` extension APIs. They follow the standard structure given by the webview documentation: https://code.visualstudio.com/api/extension-guides/webview.
283+
284+
### Importing css
285+
286+
css imports for non vue webviews should be imported when generating the webview provider html, rather than loaded inside of the javascript otherwise you will get "Error: Cannot find module 'some/path/to/my.css'" when running the e2e tests:
287+
288+
e.g. when creating the html do:
289+
290+
```ts
291+
// foo.js
292+
export function foo() {
293+
// some javascript actions
294+
}
295+
296+
// webview.ts
297+
const myCSS = webviewView.webview.asWebviewUri(
298+
vscode.Uri.joinPath(globals.context.extensionUri, 'resources', 'mycss.css')
299+
)
300+
301+
webviewView.webview.html = `
302+
<html>
303+
<head>
304+
<link rel="stylesheet" href="${myCSS.toString()}">
305+
</head>
306+
<body>
307+
<script src="./foo.js">
308+
foo()
309+
</script>
310+
</body>
311+
</html>
312+
`
313+
```
314+
315+
rather than:
316+
317+
```ts
318+
// foo.js
319+
import 'resources/mycss.css'
320+
321+
export function foo() {
322+
// some javascript actions
323+
}
324+
325+
// webview.ts
326+
webviewView.webview.html = `
327+
<html>
328+
<body>
329+
<script src="./foo.js">
330+
foo()
331+
</script>
332+
</body>
333+
</html>
334+
`
335+
```
336+
280337
### Testing
281338

282339
Currently only manual testing is done. Future work will include setting up some basic unit testing capacity via `JSDOM` and `Vue Testing Library`. Strict type-checking may also be enforced on SFCs; currently the type-checking only exists locally due to gaps in the type definitions for the DOM provided by Vue/TypeScript.

0 commit comments

Comments
 (0)