mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 01:38:19 +08:00
ui: monaco: upgrade to 0.57, drop monaco-editor-webpack-plugin
- Migrate entry points to the 0.57 exports scheme (monaco-editor/editor, languages/features/typescript/register) - Wire workers via the official MonacoEnvironment.getWorker + new Worker(new URL(...)) integration; webpack emits them as shared-chunk classic workers (chrome 70 compatible), total assets -21% - Keep css/html/json language features (register.all) and route their worker labels; json is used by the cmeditor textareas - Replace removed esm/vs/nls.messages with an inline implementation in the nls shim - Drop MinChunkSizePlugin: it merged worker chunks into the main chunk and broke the runtime id module (webpack#15416) - Remove monaco-editor-webpack-plugin dependency - loadMonaco() now returns the loaded feature module exports, e.g. loadMonaco(['typescript']).typescript.javascriptDefaults
This commit is contained in:
1 parent
80638bf9ab
commit
489b2dbeec
11 files changed
+103
-42
No files matched your search
@@ -32,7 +32,11 @@ const loaders = {
|
||||
if (resource) setLocaleData(resource);
|
||||
},
|
||||
markdown: () => import('./languages/markdown'),
|
||||
typescript: () => import('./languages/typescript').then((m) => m.loadTypes()),
|
||||
typescript: async () => {
|
||||
const m = await import('./languages/typescript');
|
||||
await m.loadTypes();
|
||||
return m;
|
||||
},
|
||||
yaml: () => import('./languages/yaml'),
|
||||
external: async (monaco, feat) => {
|
||||
for (const item of await getFeatures(`monaco-${feat}`)) {
|
||||
@@ -49,7 +53,13 @@ const loaders = {
|
||||
|
||||
let loadPromise = Promise.resolve();
|
||||
|
||||
export async function load(features = ['markdown']) {
|
||||
export async function load(features = ['markdown']): Promise<{
|
||||
monaco: typeof import('monaco-editor/editor');
|
||||
registerAction: typeof import('./index').registerAction;
|
||||
customOptions: typeof import('./index').customOptions;
|
||||
renderMarkdown: typeof import('./index').renderMarkdown;
|
||||
[feature: string]: any;
|
||||
}> {
|
||||
let s = Date.now();
|
||||
await loadPromise;
|
||||
let resolve;
|
||||
@@ -59,6 +69,7 @@ export async function load(features = ['markdown']) {
|
||||
console.log('Loading monaco editor');
|
||||
}
|
||||
const res = await import('./index');
|
||||
const featureExports: Record<string, any> = {};
|
||||
if (!loaded) {
|
||||
console.log('Loaded monaco editor in', Date.now() - s, 'ms');
|
||||
loaded = [];
|
||||
@@ -75,7 +86,7 @@ export async function load(features = ['markdown']) {
|
||||
s = Date.now();
|
||||
console.log('Loading monaco feature:', feat);
|
||||
try {
|
||||
if (loaders[feat]) await loaders[feat]();
|
||||
if (loaders[feat]) featureExports[feat] = await loaders[feat]();
|
||||
else await loaders.external(res.default, feat);
|
||||
console.log('Loaded monaco feature:', feat, 'in', Date.now() - s, 'ms');
|
||||
loaded.push(feat);
|
||||
@@ -90,6 +101,7 @@ export async function load(features = ['markdown']) {
|
||||
registerAction: res.registerAction,
|
||||
customOptions: res.customOptions,
|
||||
renderMarkdown: res.renderMarkdown,
|
||||
...featureExports,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user