Skip to content

Commit efaf06c

Browse files
author
Loïc Mangeonjean
committed
doc: mention shadow dom in documentation
1 parent 3ea57ae commit efaf06c

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,75 @@ npm run start:debugServer
323323

324324
See the [VSCode Server](https://github.com/CodinGame/monaco-vscode-api/wiki/How-to-install-and-use-VSCode-server-with-monaco‐vscode‐api) wiki page.
325325

326+
## Shadow dom (⚠️ beta ⚠️)
327+
328+
The library supports shadow-dom.
329+
330+
⚠️ VSCode itself does support shadow dom, and there are multiple parts that needed to be patched in order for it to work.
331+
332+
There are multiple benefits of using it:
333+
- Your custom global style won't impact the VSCode workbench style (for instance if you did override the default [box-sizing](https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing))
334+
- The VSCode styles won't impact other parts of your app
335+
- You page head won't be polluted with dozen of css files from VSCode
336+
337+
### How to use it
338+
339+
If the provided container element is a child of a shadow dom element, the styles will be injected in both the main page and the shadow root. That's it.
340+
341+
### Prerequisites
342+
343+
In order to be able to load the static css files in the shadow dom as well. Your bundler configuration needs to be adapted so that importing css files doesn't load their content in the page head, but instead just returns the file content as default (either as a string or a `CSSStyleSheet`). It can be achieved with most bundlers with some configurations.
344+
345+
Note that the bundler should still resolve references assets in the css files, so you can just the `raw` loader, on the `assets/source` webpack module type.
346+
347+
#### Webpack
348+
349+
Add this rule in your configuration:
350+
351+
```typescript
352+
{
353+
test: /node_modules\/(@codingame\/monaco-vscode|vscode|monaco-editor).*\.css$/,
354+
use: [
355+
{
356+
loader: 'css-loader',
357+
options: {
358+
esModule: false,
359+
exportType: 'css-style-sheet', // or 'string', both are working
360+
url: true,
361+
import: true
362+
}
363+
}
364+
]
365+
}
366+
```
367+
368+
You should also make sure that no other loader is interfering with it, by either use a `oneOf` or exclusing those files in the other css loaders.
369+
370+
#### Vite
371+
372+
Add this plugin in your configuration:
373+
374+
```typescript
375+
{
376+
name: 'load-vscode-css-as-string',
377+
enforce: 'pre',
378+
async resolveId(source, importer, options) {
379+
const resolved = (await this.resolve(source, importer, options))!
380+
if (
381+
resolved.id.match(
382+
/node_modules\/(@codingame\/monaco-vscode|vscode|monaco-editor).*\.css$/
383+
)
384+
) {
385+
return {
386+
...resolved,
387+
id: resolved.id + '?inline'
388+
}
389+
}
390+
return undefined
391+
}
392+
}
393+
```
394+
326395
## Troubleshooting
327396

328397
If something doesn't work, make sure to check out the [Troubleshooting](https://github.com/CodinGame/monaco-vscode-api/wiki/Troubleshooting) wiki page.

docs/vscode_monaco_upgrade.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
- Update dependencies
3131
- Implement improvements dependening on the new features available from vscode (optional)
3232
- Don't forget to check the `Window` output (in the `OUTPUT` panel tab) to check for errors
33+
- Check all possibile combinations
34+
- Full workbench mode or not
35+
- Shadow dom mode or not
36+
- Using VSCode server
37+
- Using HTML file system provider
38+
- ...
3339

3440
## monaco-vscode-api demo
3541

0 commit comments

Comments
 (0)