mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 16:15:41 +01:00
Fixes #795
This commit is contained in:
parent
cf3e5fdad4
commit
b5607fec63
1 changed files with 50 additions and 13 deletions
|
|
@ -8,6 +8,41 @@ If you are hosting your `.js` on a different domain (e.g. on a CDN) than the HTM
|
||||||
|
|
||||||
Assuming the HTML lives on `www.mydomain.com` and the editor is hosted on `www.mycdn.com`.
|
Assuming the HTML lives on `www.mydomain.com` and the editor is hosted on `www.mycdn.com`.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
# Option 1: Use a data: worker URI
|
||||||
|
|
||||||
|
* `https://www.mydomain.com/index.html`:
|
||||||
|
```html
|
||||||
|
<script type="text/javascript" src="http://www.mycdn.com/monaco-editor/min/vs/loader.js"></script>
|
||||||
|
<script>
|
||||||
|
require.config({ paths: { 'vs': 'http://www.mycdn.com/monaco-editor/min/vs' }});
|
||||||
|
|
||||||
|
// Before loading vs/editor/editor.main, define a global MonacoEnvironment that overwrites
|
||||||
|
// the default worker url location (used when creating WebWorkers). The problem here is that
|
||||||
|
// HTML5 does not allow cross-domain web workers, so we need to proxy the instantiation of
|
||||||
|
// a web worker through a same-domain script
|
||||||
|
window.MonacoEnvironment = {
|
||||||
|
getWorkerUrl: function(workerId, label) {
|
||||||
|
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
|
||||||
|
self.MonacoEnvironment = {
|
||||||
|
baseUrl: 'http://www.mycdn.com/monaco-editor/min/vs'
|
||||||
|
};
|
||||||
|
importScripts('http://www.mycdn.com/monaco-editor/min/vs/base/worker/workerMain.js');`
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
require(["vs/editor/editor.main"], function () {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
# Option 2: Host on your domain a worker proxy
|
||||||
|
|
||||||
* `https://www.mydomain.com/index.html`:
|
* `https://www.mydomain.com/index.html`:
|
||||||
```html
|
```html
|
||||||
<script type="text/javascript" src="http://www.mycdn.com/monaco-editor/min/vs/loader.js"></script>
|
<script type="text/javascript" src="http://www.mycdn.com/monaco-editor/min/vs/loader.js"></script>
|
||||||
|
|
@ -38,4 +73,6 @@ self.MonacoEnvironment = {
|
||||||
importScripts('www.mycdn.com/monaco-editor/min/vs/base/worker/workerMain.js');
|
importScripts('www.mycdn.com/monaco-editor/min/vs/base/worker/workerMain.js');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
That's it. You're good to go! :)
|
That's it. You're good to go! :)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue