rollup-monaco-bundler is a specialized Rollup utility designed to bundle `monaco-editor` dependencies, particularly focusing on generating UMD-formatted output. Its core differentiator is the provision for dynamic runtime National Language Support (NLS) injection, enabling `monaco-editor` to load language packs at runtime rather than bundling all of them upfront. The package, currently at version 1.0.2, appears to be in maintenance mode with its last notable activity around March 2025. Unlike other Monaco-specific Rollup plugins which might focus solely on bundling, this package explicitly targets the externalization of Monaco dependencies and efficient NLS handling for optimized bundle sizes in web applications. It's best suited for projects that require `monaco-editor` in a UMD context and need fine-grained control over internationalization.
npm install rollup-monaco-bundlerVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic Rollup configuration using `monacoNlsInject` to bundle `monaco-editor` with dynamic NLS, outputting a UMD bundle.
Review `monaco-editor`'s changelog for breaking changes related to its module format. Ensure your Rollup configuration explicitly handles ESM imports if using modern Monaco versions, potentially requiring additional plugins like `@rollup/plugin-commonjs` and `@rollup/plugin-node-resolve` configured correctly, and consider if `rollup-monaco-bundler` still meets your needs for newer Monaco versions.
Always include `@rollup/plugin-typescript`, `@rollup/plugin-node-resolve`, and `@rollup/plugin-commonjs` in your Rollup configuration's `plugins` array. Ensure `@rollup/plugin-node-resolve` and `@rollup/plugin-commonjs` are placed before `monacoNlsInject` and any custom source processing plugins. For TypeScript, `plugin-typescript` should typically be early.
Utilize Monaco's own options to include only necessary languages and features. Consider dynamically importing the Monaco editor only when needed. Configure Rollup's `external` option to exclude Monaco if you intend to load it from a CDN or a separate bundle.
Write your `rollup.config.ts` file using ES Module syntax (`import`/`export default`). If you need CommonJS-specific variables, you may need to use `import.meta.url` and `path` utilities to derive them for ESM contexts.
Ensure `@rollup/plugin-commonjs` is installed and included in your `rollup.config.ts` plugins array, placed *after* `@rollup/plugin-node-resolve` and *before* `@rollup/plugin-typescript` if both are present. You might need to add specific `namedExports` configurations to `@rollup/plugin-commonjs` for problematic modules.
Ensure your Rollup configuration correctly handles copying or bundling worker scripts to the output directory and that the Monaco editor's global configuration (`monaco.config`) points to the correct `vs` path where these workers are located. This might involve using `rollup-plugin-copy` or similar.
Ensure `monaco-editor` is loaded consistently, either entirely via a bundler (using `rollup-monaco-bundler` and other plugins) or entirely via a CDN. Avoid duplicate or conflicting `monaco.config` calls. Verify that the Monaco loader configuration, if used, is applied correctly before editor initialization.