|
1 | | -# monaco-editor-esm |
2 | | -Real ESM version of vscode monaco editor |
| 1 | +# monaco-editor-esm |
| 2 | + |
| 3 | +## Real ESM version of Monaco Editor |
| 4 | + |
| 5 | +This package provides a true ESM (EcmaScript Module) build of the [Monaco Editor](https://github.com/microsoft/monaco-editor), suitable for modern build tools and direct browser usage. All JavaScript modules are available in the `/esm` directory, and all required CSS files are in `/min`. |
| 6 | + |
| 7 | +### Why ESM? |
| 8 | +- Native ESM modules allow for better tree-shaking, direct browser imports, and compatibility with modern bundlers (Webpack, Rollup, Vite, etc.). |
| 9 | +- The official Monaco Editor package is not fully ESM and includes AMD/CommonJS code and non-standard CSS imports. |
| 10 | + |
| 11 | +### Usage |
| 12 | + |
| 13 | +#### With a Bundler (Webpack, Rollup, Vite, etc.) |
| 14 | +1. Install the package: |
| 15 | + ```sh |
| 16 | + npm install monaco-editor-esm |
| 17 | + ``` |
| 18 | +2. Import the editor in your code: |
| 19 | + ```js |
| 20 | + import * as monaco from 'monaco-editor-esm/esm/vs/editor/editor.main.js'; |
| 21 | + ``` |
| 22 | +3. Make sure to load the required CSS from `/min`: |
| 23 | + ```js |
| 24 | + import 'monaco-editor-esm/min/vs/editor/editor.main.css'; |
| 25 | + ``` |
| 26 | + Or include it in your HTML: |
| 27 | + ```html |
| 28 | + <link rel="stylesheet" href="node_modules/monaco-editor-esm/min/vs/editor/editor.main.css"> |
| 29 | + ``` |
| 30 | + |
| 31 | +#### Directly in the Browser |
| 32 | +- You can import modules from `/esm` using `<script type="module">`, but **CSS imports in JS are not natively supported in browsers**. You must manually include the CSS in your HTML: |
| 33 | + ```html |
| 34 | + <link rel="stylesheet" href="path/to/min/vs/editor/editor.main.css"> |
| 35 | + <script type="module"> |
| 36 | + import * as monaco from './esm/vs/editor/editor.main.js'; |
| 37 | + // ... |
| 38 | + </script> |
| 39 | + ``` |
| 40 | + |
| 41 | +### CSS Import Caveats |
| 42 | +- The ESM modules may contain `import './file.css'` statements, which are not yet supported natively in browsers or Node.js. Most bundlers can handle these imports with the appropriate loader/plugin. |
| 43 | +- If you use the modules directly in the browser, you must include the CSS manually as shown above. |
| 44 | +- For more background, see the [discussion on ESM and CSS loading](https://github.com/microsoft/monaco-editor/issues/886#issuecomment-4248483831). |
| 45 | + |
| 46 | +### Limitations |
| 47 | +- Some features may require additional configuration for web workers. See Monaco Editor documentation for details. |
| 48 | +- The ESM build is not guaranteed to be 100% compatible with all Monaco Editor plugins or extensions. |
| 49 | + |
| 50 | +### License |
| 51 | +MIT |
0 commit comments