npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tomjs/vscode-extension-webview

v2.0.0

Published

When using 'webview.html' in vscode extension development, 'HMR' of vue/react is supported.

Downloads

1,234

Readme

@tomjs/vscode-extension-webview

npm node-current (scoped) NPM

English | 中文

vscode 扩展开发使用 webview.html 时,支持 vue/reactHMR

由于 webview.html 限制,无法直接使用 vue/reactHMR,所以需要做一些特殊处理来实现。在返回 html 的内容中添加 <iframe> 标签,并将 src 设置为 http://localhost:8080,这样就可以实现 HMR。客户端通过 postMessage 向父级 webview 发送消息,来实现 acquireVsCodeApi 的 API。

其他也可以通过监听前端代码变化,通过 commands.executeCommand('workbench.action.webview.reloadWebviewAction') 刷新前端代码。

如果使用 vite 开发,推荐 @tomjs/vite-plugin-vscode

安装

# pnpm
pnpm add @tomjs/vscode-extension-webview

# yarn
yarn add @tomjs/vscode-extension-webview

# npm
npm i @tomjs/vscode-extension-webview

使用

extension

import getHtml from '@tomjs/vscode-extension-webview';

const panel = window.createWebviewPanel('showHelloWorld', 'Hello World', ViewColumn.One, {
  enableScripts: true,
  localResourceRoots: [Uri.joinPath(extensionUri, 'dist/webview')],
});

if (process.env.NODE_ENV === 'development') {
  panel.webview.html = getHtml({
    serverUrl: `http://localhost:5173`,
  });
} else {
  panel.webview.html = /* html */ `
<!doctype html>
  <html lang="en">
</html>`;
}

将客户端代码放到 vue/reactmain.ts 放在顶部。

// eslint-disable-next-line simple-import-sort/imports
import '@tomjs/vscode-extension-webview/client';

文档

示例

先执行以下命令安装依赖,并生成库文件:

pnpm install
pnpm build

打开 examples 目录,有 vuereact 示例。

重要说明

v2.0.0

破坏性更新:

  • 模拟的 acquireVsCodeApi@types/vscode-webviewacquireVsCodeApi 保持一致,改用 sessionStorage.getItemsessionStorage.setItem 来实现 getStatesetState