{"name":"@monaco-editor/loader","version":"1.7.0","description":"the library aims to setup monaco editor into your browser","main":"lib/cjs/index.js","module":"lib/es/index.js","unpkg":"lib/umd/monaco-loader.min.js","jsdelivr":"lib/umd/monaco-loader.min.js","types":"lib/types.d.ts","repository":{"type":"git","url":"git+https://github.com/suren-atoyan/monaco-loader.git"},"homepage":"https://github.com/suren-atoyan/monaco-loader.git","author":{"name":"Suren Atoyan","email":"contact@surenatoyan.com"},"license":"MIT","scripts":{"test":"jest","test-watch":"npm run build && jest --watch","coverage":"jest --collect-coverage","lint":"npx eslint src","prepublishOnly":"npm test && npm run lint && npm run build","build":"rollup -c && cp ./src/types.d.ts ./lib/","prepare":"husky"},"keywords":["monaco","editor","loader","monaco-editor","monaco editor"],"devDependencies":{"@babel/core":"^7.25.0","@babel/preset-env":"^7.25.0","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-node-resolve":"^15.3.0","@rollup/plugin-replace":"^6.0.1","@rollup/plugin-terser":"^0.4.4","babel-jest":"^29.7.0","babel-loader":"^9.2.1","eslint":"^9.14.0","husky":"^9.1.6","jest":"^29.7.0","rollup":"^4.24.0"},"dependencies":{"state-local":"^1.0.6"},"_id":"@monaco-editor/loader@1.7.0","gitHead":"49397b07c84a764a239012e784fae9372af8949a","bugs":{"url":"https://github.com/suren-atoyan/monaco-loader/issues"},"_nodeVersion":"22.16.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-gIwR1HrJrrx+vfyOhYmCZ0/JcWqG5kbfG7+d3f/C1LXk2EvzAbHSg3MQ5lO2sMlo9izoAZ04shohfKLVT6crVA==","shasum":"967aaa4601b19e913627688dfe8159d57549e793","tarball":"http://registry-npm.ywwl.com/@monaco-editor/loader/download/@monaco-editor/loader-1.7.0.tgz","fileCount":36,"unpackedSize":106501,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCID7CDmCRrKc67dBnetfKtlV/tGa8X9/AiiLCp8iR3eLUAiB09nBxpX/R85qWNBKr9TqebsNepr9WC/n/FzTHdFuIBQ=="}],"size":25128,"noattachment":false,"key":"/@monaco-editor/loader/-/@monaco-editor/loader-1.7.0.tgz"},"_npmUser":{"name":"surenat","email":"contact@surenatoyan.com"},"directories":{},"maintainers":[{"name":"surenat","email":"contact@surenatoyan.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/loader_1.7.0_1763709347226_0.021255749356547282"},"_hasShrinkwrap":false,"readme":"# @monaco-editor/loader &middot; [![monthly downloads](https://img.shields.io/npm/dm/@monaco-editor/loader)](https://www.npmjs.com/package/@monaco-editor/loader) [![gitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/suren-atoyan/monaco-loader/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/@monaco-editor/loader.svg?style=flat)](https://www.npmjs.com/package/@monaco-editor/loader) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/suren-atoyan/monaco-loader/pulls)\n\nThe utility to easy setup `monaco-editor` into your browser\n\n## Synopsis\n\nConfigure and download monaco sources via its loader script, without needing to use webpack's (or any other module bundler's) configuration files\n\n## Motivation\n\nIt's been a while we are working with `monaco editor`. It's a great library and provides a powerful editor out of the box. Anyway, there were couple of problems related to the setup process. The main problem is the need to do some additional `webpack` configuration; that's not bad, but some quite useful tools, like `CRA`, aren't happy with that fact. The library [`@monaco-editor/react`](https://github.com/suren-atoyan/monaco-react) was being created to solve that problem - `monaco editor wrapper for easy/one-line integration with React applications without needing to use webpack's (or any other module bundler's) configuration files`. In that library, there was a utility that cares about the initialization process of monaco and overcomes the additional use of webpack configuration. That utility grows over time and now it's a separate library. Now, you can easily setup monaco into your browser, create your own editors, wrappers for React/Vue/Angular of whatever you want.\n\n## How it works\n\nMonaco editor provides a script called `loader`, which itself provides tooling to download monaco sources. The library, under the hood, handles the configuration and loading part and gives us an easy-to-use API to interact with it\n\n## Documentation\n\n#### Contents\n\n* [Installation](#installation)\n* [Introduction](#introduction)\n* [Usage](#usage)\n  * [.config](#config)\n  * [.init](#init)\n* [Notes](#notes)\n  * [For `electron` users](#for-electron-users)\n  * [For `Next.js` users](#for-nextjs-users)\n\n### Installation\n\n```bash\nnpm install @monaco-editor/loader\n```\n\nor\n\n```bash\nyarn add @monaco-editor/loader\n```\n\nNOTE: For TypeScript type definitions, this package uses the [monaco-editor](https://www.npmjs.com/package/monaco-editor) package as a peer dependency. So, if you need types and don't already have the [monaco-editor](https://www.npmjs.com/package/monaco-editor) package installed, you will need to do so.\n\n### Introduction\n\nThe library exports types and the utility called `loader`, the last one has two methods\n\n* [.config](#config)\n* [.init](#init)\n\n### Usage\n\n```javascript\nimport loader from '@monaco-editor/loader';\n\nloader.init().then(monaco => {\n  monaco.editor.create(/* editor container, e.g. document.body */, {\n    value: '// some comment',\n    language: 'javascript',\n  });\n});\n```\n\n[codesandbox](https://codesandbox.io/s/simple-usage-os49p)\n\n#### .config\n\nBy using the `.config` method we can configure the monaco loader. By default all sources come from CDN, you can change that behavior and load them from wherever you want\n\n```javascript\nimport loader from '@monaco-editor/loader';\n\n// you can change the source of the monaco files\nloader.config({ paths: { vs: '...' } });\n\n// you can configure the locales\nloader.config({ 'vs/nls': { availableLanguages: { '*': 'de' } } });\n\n// or\nloader.config({\n  paths: {\n    vs: '...',\n  },\n  'vs/nls' : {\n    availableLanguages: {\n      '*': 'de',\n    },\n  },\n});\n\nloader.init().then(monaco => { /* ... */ });\n```\n\n[codesandbox](https://codesandbox.io/s/config-o6zn6)\n\n#### Configure the loader to load the monaco as an npm package\n\n```javascript\nimport loader from '@monaco-editor/loader';\nimport * as monaco from 'monaco-editor';\n\nloader.config({ monaco });\n\nloader.init().then(monacoInstance => { /* ... */ });\n```\n\n[codesandbox](https://codesandbox.io/s/npm-gswrvh)\n\n#### .init\n\nThe `.init` method handles the initialization process. It returns the monaco instance, wrapped with cancelable promise\n\n```javascript\nimport loader from '@monaco-editor/loader';\n\nloader.init().then(monaco => {\n  console.log('Here is the monaco instance', monaco);\n});\n```\n\n[codesandbox](https://codesandbox.io/s/init-q2ipt)\n\n```javascript\nimport loader from '@monaco-editor/loader';\n\nconst cancelable = loader.init();\n\ncancelable.then(monaco => {\n  console.log('You will not see it, as it is canceled');\n});\n\ncancelable.cancel();\n```\n\n[codesandbox](https://codesandbox.io/s/init-cancelable-9o42y)\n\n#### Notes\n\n##### For `electron` users\n\nIn general it works fine with electron, but there are several cases that developers usually face to and sometimes it can be confusing. Here they are:\n\n1) **Download process fails** or if you use @monaco-editor/react **You see loading screen stuck**\nUsually, it's because your environment doesn't allow you to load external sources. By default, it loads monaco sources from CDN. You can see the [default configuration](https://github.com/suren-atoyan/monaco-loader/blob/master/src/config/index.js#L3). But sure you can change that behavior; the library is fully configurable. Read about it [here](https://github.com/suren-atoyan/monaco-loader#config). So, if you want to download it from your local files, you can do it like this:\n\n```javascript\nimport loader from '@monaco-editor/loader';\n\nloader.config({ paths: { vs: '../path-to-monaco' } });\n```\n\nor, if you want to use it as an npm package, you can do it like this:\n\n```javascript\nimport loader from '@monaco-editor/loader';\nimport * as monaco from 'monaco-editor';\n\nloader.config({ monaco });\n\nloader.init().then(monacoInstance => { /* ... */ });\n```\n\n2) **Based on your electron environment it can be required to have an absolute URL**\nThe utility function taken from [here](https://github.com/microsoft/monaco-editor-samples/blob/master/electron-amd-nodeIntegration/electron-index.html) can help you to achieve that. Let's imagine you have `monaco-editor` package installed and you want to load monaco from the `node_modules` rather than from CDN: in that case, you can write something like this:\n\n```javascript\nfunction ensureFirstBackSlash(str) {\n    return str.length > 0 && str.charAt(0) !== '/'\n        ? '/' + str\n        : str;\n}\n\nfunction uriFromPath(_path) {\n    const pathName = path.resolve(_path).replace(/\\\\/g, '/');\n    return encodeURI('file://' + ensureFirstBackSlash(pathName));\n}\n\nloader.config({\n  paths: {\n    vs: uriFromPath(\n      path.join(__dirname, '../node_modules/monaco-editor/min/vs')\n    )\n  }\n});\n```\n\nor, just use it as an npm package.\n\nThere were several issues about this topic that can be helpful too - [1](https://github.com/suren-atoyan/monaco-react/issues/48) [2](https://github.com/suren-atoyan/monaco-react/issues/12) [3](https://github.com/suren-atoyan/monaco-react/issues/58) [4](https://github.com/suren-atoyan/monaco-react/issues/87)\n\nAnd if you use `electron` with `monaco` and have faced an issue different than the above-discribed ones, please let us know to make this section more helpful.\n\n##### For `Next.js` users\n\nThe part of the source that should be pre-parsed is optimized for server-side rendering, so, in usual cases, it will work fine, but if you want to have access, for example, to [`monacoInstance`](#config) you should be aware that it wants to access the `document` object, and it requires browser environment. Basically you just need to avoid running that part out of browser environment, there are several ways to do that. One of them is described [here](https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr).\n\nAnd if you use `monaco` with `Next.js` and have faced an issue different than the above-described one, please let us know to make this section more helpful.\n\n## License\n\n[MIT](./LICENSE)\n","publish_time":1763709347432,"_cnpm_publish_time":1763709347432,"dist-tags":{"latest":"1.7.0"}}