{"library":"monaco-prettier","title":"monaco-prettier","description":"Integrates Prettier formatting into the Monaco editor. v1.0.0 (initial release) provides document and range formatting via a dedicated Monaco worker for performance. Requires a peer dependency on Prettier v3+. Configure per-language parsers and Prettier options. Unlike other Monaco formatter setups, this package uses a web worker to avoid blocking the UI, and supports any Prettier plugin (e.g., babel, estree, prettier-plugin-svelte).","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install monaco-prettier"],"cli":null},"imports":["import { configureMonacoPrettier } from 'monaco-prettier'","import { setup } from 'monaco-prettier/worker'","import monacoPrettier from 'monaco-prettier'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// prettier.worker.js\nimport { setup } from 'monaco-prettier/worker';\nimport * as babel from 'prettier/plugins/babel';\nimport * as estree from 'prettier/plugins/estree';\nsetup([babel, estree]);\n\n// app.js\nimport * as monaco from 'monaco-editor';\nimport { configureMonacoPrettier } from 'monaco-prettier';\n\nglobalThis.MonacoEnvironment = {\n  getWorker(moduleId, label) {\n    if (label === 'prettier') {\n      return new Worker(new URL('prettier.worker.js', import.meta.url));\n    }\n    return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url));\n  }\n};\n\nmonaco.languages.typescript.javascriptDefaults.setModeConfiguration({\n  documentFormattingEdits: false,\n  documentRangeFormattingEdits: false\n});\n\nconfigureMonacoPrettier(monaco, {\n  parsers: {\n    javascript: 'babel',\n    typescript: 'babel-ts'\n  },\n  prettier: {\n    semi: false,\n    singleQuote: true\n  }\n});\n\nmonaco.editor.createModel('const x = 1', 'javascript', monaco.Uri.parse('file:///test.js'));","lang":"javascript","description":"Shows how to set up a Prettier worker and configure Monaco to use it for formatting JavaScript files.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}