You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Monaco-editor is a library that is constructed using code from vscode and goes through an intense treeshaking process.
37
32
38
33
However, due to the inclusion of additional code from VSCode in this library that utilizes internal modules bundled in monaco, this treeshaking is a problem here.
39
34
40
-
To **tree-mend** (to **un**treeshake it) monaco-editor, this library provide a script that will apply a patch on the local installation of monaco-editor, restoring all the code that was treeshaken during the monaco-editor build process
35
+
To **tree-mend** (to **un**treeshake it) monaco-editor, this library provides a script that will apply a patch on the local installation of monaco-editor, restoring all the code that was treeshaken during the monaco-editor build process
36
+
37
+
## Troubleshooting
38
+
39
+
### If you use Vite
40
+
41
+
This library uses a lot the `new URL('asset.extension', import.meta.url)` syntax which [is supported by vite](https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url)
42
+
43
+
While it works great in `build` mode (because rollup is used), there is some issues in `watch`` mode:
44
+
- import.meta.url is not replaced while creating bundles, it is an issue when the syntax is used inside a dependency
45
+
- vite is still trying to inject/transform javascript assets files, breaking the code by injecting ESM imports in commonjs files
46
+
47
+
There are workarounds for both:
48
+
49
+
- We can help vite by replacing `import.meta.url` by the original module path (you need the --experimental-import-meta-resolve note option):
50
+
```typescript
51
+
{
52
+
...
53
+
optimizeDeps: {
54
+
esbuildOptions: {
55
+
plugins: [{
56
+
name: 'import.meta.url',
57
+
setup ({ onLoad }) {
58
+
// Help vite that bundles/move files in dev mode without touching `import.meta.url` which breaks asset urls
0 commit comments