|
|
|
@ -194,36 +194,32 @@ Adding monaco editor to [Vite](https://vitejs.dev/) is simple since it has built
|
|
|
|
|
import * as monaco from 'monaco-editor';
|
|
|
|
|
|
|
|
|
|
self.MonacoEnvironment = {
|
|
|
|
|
getWorker: function(workerId, label) {
|
|
|
|
|
|
|
|
|
|
const getWorkerModule = (moduleUrl, label) => {
|
|
|
|
|
return new Worker(self.MonacoEnvironment.getWorkerUrl(moduleUrl), {
|
|
|
|
|
name: label,
|
|
|
|
|
type: 'module'
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (label) {
|
|
|
|
|
case 'json':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/json/json.worker?worker', label);
|
|
|
|
|
case 'css':
|
|
|
|
|
case 'scss':
|
|
|
|
|
case 'less':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/css/css.worker?worker', label);
|
|
|
|
|
case 'html':
|
|
|
|
|
case 'handlebars':
|
|
|
|
|
case 'razor':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/html/html.worker?worker', label);
|
|
|
|
|
case 'typescript':
|
|
|
|
|
case 'javascript':
|
|
|
|
|
return getWorkerModule(
|
|
|
|
|
'/monaco-editor/esm/vs/language/typescript/ts.worker?worker',
|
|
|
|
|
label
|
|
|
|
|
);
|
|
|
|
|
default:
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/editor/editor.worker?worker', label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getWorker: function (workerId, label) {
|
|
|
|
|
const getWorkerModule = (moduleUrl, label) => {
|
|
|
|
|
return new Worker(self.MonacoEnvironment.getWorkerUrl(moduleUrl), {
|
|
|
|
|
name: label,
|
|
|
|
|
type: 'module'
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (label) {
|
|
|
|
|
case 'json':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/json/json.worker?worker', label);
|
|
|
|
|
case 'css':
|
|
|
|
|
case 'scss':
|
|
|
|
|
case 'less':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/css/css.worker?worker', label);
|
|
|
|
|
case 'html':
|
|
|
|
|
case 'handlebars':
|
|
|
|
|
case 'razor':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/html/html.worker?worker', label);
|
|
|
|
|
case 'typescript':
|
|
|
|
|
case 'javascript':
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/language/typescript/ts.worker?worker', label);
|
|
|
|
|
default:
|
|
|
|
|
return getWorkerModule('/monaco-editor/esm/vs/editor/editor.worker?worker', label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
monaco.editor.create(document.getElementById('container'), {
|
|
|
|
|