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

@pikaz/transform-package-to-esmodule

v0.0.3

Published

Convert js mounted window variables to module

Readme

介绍

现有部分前端依赖库仅支持通过 <script> 标签引入,尚未提供对 ESModule (ECMAScript 模块) 的原生支持。本项目可将这些库/代码转化为能够以 ESModule 形式被导入和使用,同时保持原有的功能性和兼容性,从而快速兼容至 vite 等现代打包器。

demo 打包代码配置点击这里 copy

demo 使用打包产物代码点击这里查看

npm run build 可测试打包,npm run test 可查看打包效果

效果示例

源 js 文件(无 ESModule 支持)

const add = (a, b) => a + b;
window.exampleAdd = add;

打包后引入

import { exampleAdd } from "./exampleAdd.js";
const result = exampleAdd(1, 2);
console.log(result);

安装

with npm or yarn

yarn add @pikaz/transform-package-to-ESModule

npm i -S @pikaz/transform-package-to-ESModule

使用说明

打包 js 文件(推荐)

打包配置示例 build.js

const path = require("path");
const build = require("@pikaz/transform-package-to-ESModule");
build({
  jsPath: path.join(__dirname, "exampleAddCore.js"), //需打包的js文件路径
  keys: ["exampleAdd"], //打包的js文件挂载在window上的对象key,可传入多个,若无挂载对象则传null或不传(打包产物会自动导出这些对象)
  outPath: path.join(__dirname, "exampleAdd.js"), //打包js文件导出路径
  //也可以选择传入jsCore不打包js文件而是直接打包js代码,不推荐,js代码可能存在问题字符导致打包文件错误
  //jsCore: "const exampleAdd= (a,b)=>a+b; window.exampleAdd=exampleAdd;",
});

执行 node build.js 进行打包,得到打包文件 exampleAdd.js

使用打包文件示例 index.html

// 打包产物导出对象取决于打包配置的keys
import { exampleAdd } from "./exampleAdd.js";
const result = exampleAdd(1, 2);
console.log(result);

打包 js 代码并导出(不推荐)

import createModule from "@pikaz/transform-package-to-ESModule/createModule";
const { exampleAdd } = createModule({
  keys: ["exampleAdd"], //打包的js文件挂载在window上的对象key,可传入多个,若无挂载对象则传null或不传(打包函数会自动导出这些对象)
  jsCore: "const exampleAdd= (a,b)=>a+b;window.exampleAdd=exampleAdd;", //js代码
});
// 使用exampleAdd函数
const result = exampleAdd(1, 2);
console.log(result);