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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-sandbox

v2.0.3

Published

Vite plugin for JavaScript runtime isolation via proxy sandbox

Readme

vite-plugin-sandbox

简体中文 | English

简体中文

通过代理,将自由变量windowbodywindow.xxx 引用单独隔离沙箱环境,适合微前端等场景。

安装

npm i vite-plugin-sandbox proxy-sandbox-browser -D
# 或
pnpm add vite-plugin-sandbox proxy-sandbox-browser -D

可以与 CSS 命名空间插件配合使用:vite-plugin-sandbox-css

快速开始

vite.config.ts 中启用:

import { defineConfig } from 'vite';
import sandbox from 'vite-plugin-sandbox';
import cssSandbox from 'vite-plugin-sandbox-css';

export default defineConfig({
  plugins: [
    sandbox({
      code: 'app1',
    }),
    cssSandbox({
      prefix: '.app1',
      overlaySelectors: ['.modal', '.popup', '.el-', '.ant-'],
    }),
  ],
});

配置项

sandbox(options: SandboxOptions)

  • code:应用标识, 用于区分不同模块。
  • include/exclude:按 @rollup/pluginutilscreateFilter 规则筛选要代理的模块路径。
  • sandboxOptions.globalVarWhiteList:全局变量白名单,不被代理的全局变量,如 window.xx 引用。默认 []
  • sandboxOptions.disableScriptSandbox:是否禁用动态加载脚本代理,默认 false

变量代理与效果

  • 顶层自由变量:凡未在当前作用域声明的标识符(如 documentconsoleDatesetTimeout 等),会被重写为 __vite_sandbox_win__.proxy.<标识符>
  • window:会被重写为 __vite_sandbox_win__.proxy,因此 window.xxx 等价于 __vite_sandbox_win__.proxy.xxx,所有属性访问与方法调用均在沙箱环境内完成。
  • window.xxx:如 window.alertwindow.fetchwindow.localStorage 会重写为 __vite_sandbox_win__.proxy.alert/fetch/localStorage,由运行时决定具体隔离与白名单行为(可通过 sandboxOptions.globalVarWhiteList 配置例外)。

示例(代码改写前后对比,仅展示关键行):

// 原始代码
document.title = 'Hello';
window.alert('hi');
console.log(Date.now());

// 重写后(简化展开)
import __vite_sandbox_win__ from 'proxy-sandbox-browser?virtual=true';
__vite_sandbox_win__.proxy.document.title = 'Hello';
__vite_sandbox_win__.proxy.alert('hi');
__vite_sandbox_win__.proxy.console.log(__vite_sandbox_win__.proxy.Date.now());

English

Overview

  • Isolates free variables and references to window, document.body, and window.xxx into a proxy-based sandbox environment, suitable for micro-frontends.

Install

npm i vite-plugin-sandbox proxy-sandbox-browser -D
# or
pnpm add vite-plugin-sandbox proxy-sandbox-browser -D

Can be used together with the CSS namespace plugin: vite-plugin-sandbox-css.

Quick Start

import { defineConfig } from 'vite';
import sandbox from 'vite-plugin-sandbox';
import cssSandbox from 'vite-plugin-sandbox-css';

export default defineConfig({
  plugins: [
    sandbox({
      code: 'app1',
    }),
    cssSandbox({
      prefix: '.app1',
      overlaySelectors: ['.modal', '.popup', '.el-', '.ant-'],
    }),
  ],
});

Options

  • code: App identifier used to distinguish modules.
  • include/exclude: Filter paths to be proxied using @rollup/pluginutils createFilter.
  • sandboxOptions.globalVarWhiteList: Global variables not proxied (e.g. specific window.xx). Default [].
  • sandboxOptions.disableScriptSandbox: Whether to disable proxying for dynamically loaded scripts. Default false.

Variable Proxy & Effects

  • Free variables: Any identifier not declared in local scope (e.g. document, console, Date, setTimeout) is rewritten to __vite_sandbox_win__.proxy.<identifier> and read from the proxy window.
  • window: Rewritten to __vite_sandbox_win__.proxy, hence window.xxx becomes __vite_sandbox_win__.proxy.xxx and runs inside the sandbox.
  • window.xxx: e.g. window.alert, window.fetch, window.localStorage are rewritten to proxy counterparts; isolation and whitelisting are controlled by runtime (sandboxOptions.globalVarWhiteList).

Example (key lines before/after):

// original
document.title = 'Hello';
window.alert('hi');
console.log(Date.now());

// rewritten (simplified)
import __vite_sandbox_win__ from 'proxy-sandbox-browser?virtual=true';
__vite_sandbox_win__.proxy.document.title = 'Hello';
__vite_sandbox_win__.proxy.alert('hi');
__vite_sandbox_win__.proxy.console.log(__vite_sandbox_win__.proxy.Date.now());