Skip to content

Commit

Permalink
fix: inline code-samples for faster loading
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulthink committed Feb 9, 2023
1 parent 3e59943 commit 9029ed0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions examples/playground/src/init-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import {configureMonacoWorkers} from './configure-monaco-workers';
* dependencies (Google Maps and our marker library).
*/
async function initEditorFilesystem() {
const markerLibFiles = import.meta.glob(`../../../dist/*.d.ts`, {as: 'raw'});
const markerLibFiles = import.meta.glob(`../../../dist/*.d.ts`, {
as: 'raw',
eager: true
});

languages.typescript.typescriptDefaults.addExtraLib(
(await import('../node_modules/@types/google.maps/index.d.ts?raw')).default,
`file:///node_modules/@types/google.maps/index.d.ts`
);

for (const [path, loadFile] of Object.entries(markerLibFiles)) {
for (const [path, content] of Object.entries(markerLibFiles)) {
const editorPath = path.replace(
/^.*\/dist\//,
`file:///node_modules/${packageName}/`
);

languages.typescript.typescriptDefaults.addExtraLib(
await loadFile(),
editorPath
);
languages.typescript.typescriptDefaults.addExtraLib(content, editorPath);
}
}

Expand All @@ -41,14 +41,17 @@ type CodeSample = {
};

async function loadCodeSamples(): Promise<Record<string, CodeSample>> {
const exampleFiles = import.meta.glob('./code-samples/*.ts', {as: 'raw'});
const exampleFiles = import.meta.glob('./code-samples/*.ts', {
as: 'raw',
eager: true
});
const codeSamples: Record<string, CodeSample> = {};

for (const [path, loadFile] of Object.entries(exampleFiles)) {
for (const [path, content] of Object.entries(exampleFiles)) {
const filename = path.replace('./code-samples/', '');
const editorPath = `file:///${filename}`;
const model = editor.createModel(
await loadFile(),
content,
'typescript',
Uri.parse(editorPath)
);
Expand Down

0 comments on commit 9029ed0

Please sign in to comment.