Skip to content

Commit 75a46cf

Browse files
committed
try esm.sh
1 parent e4addd5 commit 75a46cf

File tree

6 files changed

+17
-33
lines changed

6 files changed

+17
-33
lines changed

.changeset/soft-cars-notice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
'graphiql': major
33
'@graphiql/react': minor
4-
'monaco-graphql': major
4+
'monaco-graphql': minor
55
---
66

77
replace Codemirror editor with Monaco editor and Monaco GraphQL

packages/graphiql-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"react-dom": "^18 || ^19"
5151
},
5252
"dependencies": {
53-
"monaco-editor": "^0.52.2",
53+
"monaco-editor": "^0.47",
5454
"monaco-graphql": "^1.6.1",
5555
"jsonc-parser": "^3.3.1",
5656
"prettier": "^3.5.3",

packages/graphiql/index.html

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,23 @@
3333
src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
3434
></script>
3535
<script type="module">
36-
/**
37-
* Setup workers for GraphiQL UMD bundle
38-
*/
39-
function getWorkerUrl(label) {
40-
switch (label) {
41-
case 'json':
42-
return '/dist/workers/json.worker.js';
43-
case 'graphql':
44-
return '/dist/workers/graphql.worker.js';
45-
}
46-
return '/dist/workers/editor.worker.js';
47-
}
36+
import createJSONWorker from 'https://esm.sh/monaco-editor@0.47/esm/vs/language/json/json.worker.js?worker'
37+
import createGraphQLWorker
38+
from 'https://esm.sh/monaco-graphql@2.0.0-canary-1ba7d921.0/esm/graphql.worker.js?worker'
39+
import createEditorWorker from 'https://esm.sh/monaco-editor@0.47/esm/vs/editor/editor.worker.js?worker'
4840

4941
globalThis.MonacoEnvironment = {
50-
// `MonacoEnvironment.getWorkerUrl` throws Uncaught SyntaxError: Unexpected token 'export',
51-
// we use` MonacoEnvironment getWorker` instead
5242
getWorker(_workerId, label) {
53-
console.log('setup workers in cdn');
54-
const url = new URL(getWorkerUrl(label), import.meta.url);
55-
return new Worker(url, { type: 'module' });
56-
},
57-
};
43+
console.log({ label })
44+
switch (label) {
45+
case 'json':
46+
return createJSONWorker({ name: 'json.worker' })
47+
case 'graphql':
48+
return createGraphQLWorker({ name: 'graphql.worker' })
49+
}
50+
return createEditorWorker({ name: 'editor.worker' })
51+
}
52+
}
5853
</script>
5954
<script src="/dist/index.umd.js"></script>
6055
<script type="module" src="/dist/e2e.js"></script>

packages/graphiql/src/cdn.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as GraphiQLReact from '@graphiql/react';
99
import { createGraphiQLFetcher, createLocalStorage } from '@graphiql/toolkit';
1010
import * as GraphQL from 'graphql';
1111
import { GraphiQL } from './GraphiQL';
12-
import './setup-workers/vite';
1312

1413
const majorVersion = parseInt(version.slice(0, 2), 10);
1514

packages/graphiql/vite.config.mts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ const umdConfig = defineConfig({
6363
},
6464
},
6565
},
66-
worker: {
67-
format: 'es',
68-
rollupOptions: {
69-
output: {
70-
entryFileNames: 'workers/[name].js',
71-
// Just to group worker assets, add shared/internal chunks too
72-
chunkFileNames: 'workers/[name].js',
73-
},
74-
},
75-
},
7666
});
7767

7868
const esmConfig = defineConfig({

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14487,7 +14487,7 @@ monaco-editor-webpack-plugin@^7.0.1:
1448714487
dependencies:
1448814488
loader-utils "^2.0.2"
1448914489

14490-
monaco-editor@0.47.0, monaco-editor@^0.39.0, monaco-editor@^0.52.2:
14490+
monaco-editor@0.47.0, monaco-editor@^0.39.0, monaco-editor@^0.47, monaco-editor@^0.52.2:
1449114491
version "0.47.0"
1449214492
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.47.0.tgz#39865d67e0c9fb8c6b49e760bf9caf6a6650d28e"
1449314493
integrity sha512-VabVvHvQ9QmMwXu4du008ZDuyLnHs9j7ThVFsiJoXSOQk18+LF89N4ADzPbFenm0W4V2bGHnFBztIRQTgBfxzw==

0 commit comments

Comments
 (0)