fix: 解决monaco环境变量和monaco插件的冲突 (#6283)

Co-authored-by: renjianhua <renjianhua@zuoshouyisheng.com>
This commit is contained in:
backpast 2023-03-10 15:22:45 +08:00 committed by GitHub
parent a9f3aad139
commit 72ff6bb4cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 47 deletions

View File

@ -78,31 +78,6 @@
<script type="module">
import {bootstrap} from './examples/index.jsx';
import * as monaco from 'monaco-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
self.MonacoEnvironment = {
getWorker(_, label) {
if (label === 'json') {
return new jsonWorker();
}
if (label === 'css' || label === 'scss' || label === 'less') {
return new cssWorker();
}
if (label === 'html' || label === 'handlebars' || label === 'razor') {
return new htmlWorker();
}
if (label === 'typescript' || label === 'javascript') {
return new tsWorker();
}
return new editorWorker();
}
};
window.enableAMISDebug = true;
const initialState = {};

View File

@ -16,34 +16,34 @@ import {LocaleProps, localeable} from 'amis-core';
function filterUrl(url: string) {
return url;
}
if (!(window as any).MonacoEnvironment) {
(window as any).MonacoEnvironment = {
getWorkerUrl: function (moduleId: string, label: string) {
let url = '/pkg/editor.worker.js';
(window as any).MonacoEnvironment = {
getWorkerUrl: function (moduleId: string, label: string) {
let url = '/pkg/editor.worker.js';
if (label === 'json') {
url = '/pkg/json.worker.js';
} else if (label === 'css') {
url = '/pkg/css.worker.js';
} else if (label === 'html') {
url = '/pkg/html.worker.js';
} else if (label === 'typescript' || label === 'javascript') {
url = '/pkg/ts.worker.js';
}
if (label === 'json') {
url = '/pkg/json.worker.js';
} else if (label === 'css') {
url = '/pkg/css.worker.js';
} else if (label === 'html') {
url = '/pkg/html.worker.js';
} else if (label === 'typescript' || label === 'javascript') {
url = '/pkg/ts.worker.js';
}
url = filterUrl(url);
url = filterUrl(url);
// url 有可能会插件替换成 cdn 地址比如fis3-prepackager-stand-alone-pack
if (/^https?/.test(url)) {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
// url 有可能会插件替换成 cdn 地址比如fis3-prepackager-stand-alone-pack
if (/^https?/.test(url)) {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
importScripts('${url}');`)}
`;
}
return url;
}
return url;
}
};
};
}
export function monacoFactory(
containerElement: HTMLElement,
monaco: any,