Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade playground to new worker import syntax #88

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions playground/app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { compressToURL as encode } from '@amoutonbrady/lz-string';
import { Show, onCleanup, createEffect, createSignal, JSX } from 'solid-js';

import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
import type { editor as mEditor } from 'monaco-editor';

import pkg from '../package.json';
Expand All @@ -14,21 +11,25 @@ import { Header } from './components/header';
import { parseHash } from './utils/parseHash';
import { isValidUrl } from './utils/isValidUrl';

import CompilerWorker from '../src/workers/compiler?worker';
import FormatterWorker from '../src/workers/formatter?worker';
import useZoom from '../src/hooks/useZoom';
import { isDarkTheme } from './utils/isDarkTheme';

const createWorker = (path: string) => {
return new Worker(
new URL(path, import.meta.url), {type: 'module'}
)
}

(window as any).MonacoEnvironment = {
getWorker(_moduleId: unknown, label: string) {
switch (label) {
case 'css':
return new cssWorker();
return createWorker('monaco-editor/esm/vs/language/css/css.worker');
case 'typescript':
case 'javascript':
return new tsWorker();
return createWorker('monaco-editor/esm/vs/language/typescript/ts.worker');
default:
return new editorWorker();
return createWorker('monaco-editor/esm/vs/editor/editor.worker');
}
},
};
Expand All @@ -47,8 +48,8 @@ export const App = (): JSX.Element => {
eventBus.on('sw-update', () => setNewUpdate(true));
onCleanup(() => eventBus.all.clear());

const compiler = new CompilerWorker();
const formatter = new FormatterWorker();
const compiler = createWorker('../src/workers/compiler');
const formatter = createWorker('../src/workers/formatter');

const url = new URL(location.href);
const initialTabs = parseHash(url.hash && url.hash.slice(1), defaultTabs) || defaultTabs;
Expand Down