{"id":18823001,"url":"https://github.com/tomjs/vscode-extension-webview","last_synced_at":"2026-01-19T07:30:16.309Z","repository":{"id":213265735,"uuid":"733422454","full_name":"tomjs/vscode-extension-webview","owner":"tomjs","description":"在 vscode 扩展开发使用 webview.html 时，支持 vue/react 的 HMR。When using webview.html in vscode extension development, HMR of vue/react is supported.","archived":false,"fork":false,"pushed_at":"2024-10-08T12:44:46.000Z","size":570,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-08T16:08:43.881Z","etag":null,"topics":["client","extension","patch","vscode","webview"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-19T09:45:29.000Z","updated_at":"2024-10-24T06:38:44.000Z","dependencies_parsed_at":"2023-12-21T13:11:18.624Z","dependency_job_id":"992b0001-4976-483b-9adc-f69083335a62","html_url":"https://github.com/tomjs/vscode-extension-webview","commit_stats":null,"previous_names":["tomgao365/vscode-extension-webview","tomjs/vscode-extension-webview"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvscode-extension-webview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvscode-extension-webview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvscode-extension-webview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvscode-extension-webview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomjs","download_url":"https://codeload.github.com/tomjs/vscode-extension-webview/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231811051,"owners_count":18430058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","extension","patch","vscode","webview"],"created_at":"2024-11-08T00:52:21.256Z","updated_at":"2026-01-19T07:30:16.229Z","avatar_url":"https://github.com/tomjs.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @tomjs/vscode-extension-webview\n\n[![npm](https://img.shields.io/npm/v/@tomjs/vscode-extension-webview)](https://www.npmjs.com/package/@tomjs/vscode-extension-webview) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vscode-extension-webview) ![NPM](https://img.shields.io/npm/l/@tomjs/vscode-extension-webview) **English** | [中文](./README.zh_CN.md)\n\n\u003e When using `webview.html` in `vscode` extension development, `HMR` of `vue`/`react` is supported.\n\nDue to the limitations of `webview.html`, `HMR` of `vue`/`react` cannot be used directly, so some special processing is required to achieve it. You can implement `HMR` by adding an `\u003ciframe\u003e` tag to the content that returns `html` and setting the `src` to `http://localhost:5173`. The client sends a message to the parent `webview` through `postMessage` to implement the API of [acquireVsCodeApi](https://code.visualstudio.com/api/references/vscode-api#Webview).\n\nOthers can also monitor front-end code changes and refresh the front-end code through `commands.executeCommand('workbench.action.webview.reloadWebviewAction')`.\n\nIf you use `vite` for development, [@tomjs/vite-plugin-vscode](https://www.npmjs.com/package/@tomjs/vite-plugin-vscode) is recommended\n\n## Install\n\n```bash\n# pnpm\npnpm add @tomjs/vscode-extension-webview\n\n# yarn\nyarn add @tomjs/vscode-extension-webview\n\n# npm\nnpm i @tomjs/vscode-extension-webview\n```\n\n## Usage\n\n`extension`\n\n```ts\nimport getHtml from '@tomjs/vscode-extension-webview';\n\nconst panel = window.createWebviewPanel('showHelloWorld', 'Hello World', ViewColumn.One, {\n  enableScripts: true,\n  localResourceRoots: [Uri.joinPath(extensionUri, 'dist/webview')],\n});\n\nif (process.env.NODE_ENV === 'development') {\n  panel.webview.html = getHtml({\n    serverUrl: `http://localhost:5173`,\n  });\n} else {\n  panel.webview.html = /* html */ `\n\u003c!doctype html\u003e\n  \u003chtml lang=\"en\"\u003e\n\u003c/html\u003e`;\n}\n```\n\nPlace the client code in `main.ts` of `vue`/`react` at the top.\n\n```ts\n// eslint-disable-next-line simple-import-sort/imports\nimport '@tomjs/vscode-extension-webview/client';\n```\n\n## Documentation\n\n- [index.d.ts](https://www.unpkg.com/browse/@tomjs/vscode-extension-webview/dist/index.d.ts) provided by [unpkg.com](https://www.unpkg.com).\n\n## Examples\n\nFirst execute the following command to install dependencies and generate library files:\n\n```bash\npnpm install\npnpm build\n```\n\nOpen the [examples](./examples) directory, there are `vue` and `react` examples.\n\n- [react](./examples/react)\n- [vue](./examples/vue)\n\n## Important Notes\n\n### v2.0.0\n\n**Breaking Updates:**\n\n- The simulated `acquireVsCodeApi` is consistent with the `acquireVsCodeApi` of [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview), and `sessionStorage.getItem` and `sessionStorage.setItem` are used to implement `getState` and `setState`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomjs%2Fvscode-extension-webview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomjs%2Fvscode-extension-webview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomjs%2Fvscode-extension-webview/lists"}