mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Rewrites website
This commit is contained in:
parent
5eff543347
commit
10577a0641
313 changed files with 12080 additions and 29200 deletions
98
website/src/monaco-loader.ts
Normal file
98
website/src/monaco-loader.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export function getLoadedMonaco(): typeof monaco {
|
||||
if (!monaco) {
|
||||
throw new Error("monaco is not loaded yet");
|
||||
}
|
||||
return monaco;
|
||||
}
|
||||
|
||||
export function getMonaco(): typeof monaco | undefined {
|
||||
return (window as any).monaco;
|
||||
}
|
||||
|
||||
export interface IMonacoSetup {
|
||||
loaderUrl: string;
|
||||
loaderConfigPaths: Record<string, string>;
|
||||
codiconUrl: string;
|
||||
monacoTypesUrl: string | undefined;
|
||||
}
|
||||
|
||||
let loadMonacoPromise: Promise<typeof monaco> | undefined;
|
||||
export async function loadMonaco(
|
||||
setup: IMonacoSetup = prodMonacoSetup
|
||||
): Promise<typeof monaco> {
|
||||
if (!loadMonacoPromise) {
|
||||
loadMonacoPromise = _loadMonaco(setup);
|
||||
}
|
||||
return loadMonacoPromise;
|
||||
}
|
||||
|
||||
async function _loadMonaco(setup: IMonacoSetup): Promise<typeof monaco> {
|
||||
const global = self as any;
|
||||
|
||||
if (!(global as any).require) {
|
||||
await loadScript(setup.loaderUrl);
|
||||
}
|
||||
|
||||
global.AMD = true;
|
||||
global.getCodiconPath = () => {
|
||||
return setup.codiconUrl;
|
||||
};
|
||||
|
||||
console.log("LOADER CONFIG: ");
|
||||
console.log(JSON.stringify(setup.loaderConfigPaths, null, "\t"));
|
||||
|
||||
/** @type {any} */
|
||||
const req = global.require as any;
|
||||
req.config({ paths: setup.loaderConfigPaths });
|
||||
|
||||
return new Promise((res) => {
|
||||
// First load editor.main. If it inlines the plugins, we don't want to try to load them from the server.
|
||||
req(["vs/editor/editor.main"], () => {
|
||||
req(
|
||||
[
|
||||
"vs/basic-languages/monaco.contribution",
|
||||
"vs/language/css/monaco.contribution",
|
||||
"vs/language/html/monaco.contribution",
|
||||
"vs/language/json/monaco.contribution",
|
||||
"vs/language/typescript/monaco.contribution",
|
||||
],
|
||||
() => {
|
||||
res(monaco);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loadScript(path: string): Promise<void> {
|
||||
return new Promise((res) => {
|
||||
const script = document.createElement("script");
|
||||
script.onload = () => res();
|
||||
script.async = true;
|
||||
script.type = "text/javascript";
|
||||
script.src = path;
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
}
|
||||
|
||||
export const prodMonacoSetup = getMonacoSetup(
|
||||
"node_modules/monaco-editor/min/vs"
|
||||
);
|
||||
|
||||
export function getMonacoSetup(corePath: string): IMonacoSetup {
|
||||
const loaderConfigPaths = {
|
||||
vs: `${corePath}`,
|
||||
};
|
||||
|
||||
return {
|
||||
loaderUrl: `${corePath}/loader.js`,
|
||||
loaderConfigPaths,
|
||||
codiconUrl: `${corePath}/base/browser/ui/codicons/codicon/codicon.ttf`,
|
||||
monacoTypesUrl: undefined,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue