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

mika-swc-plugin

v1.0.0

Published

use wasm module to compile jsx or ts files

Readme

mika-swc-plugin

compile ts or jsx code on brower side

Get started

npm install mika-swc-plugin

1. 针对 ts 内容简易设置

//transform typescript code:
import { useEffect, useState } from "react";
import initSwc, { transformSync } from "@swc/wasm-web";

const tsCode = `
interface User {
  name: string;
  age: number;
}

const greet = (user: User): string => {
  return \`Hello, \${user.name}!\`;
};
`;
async function importAndRunSwcOnMount() {
  await initSwc();
  const result = await transformSync(tsCode, {
    jsc: {
      parser: {
        syntax: "typescript",
        tsx: false,
      },
      target: "es2020",
    },
  });
  return result;
}
importAndRunSwcOnMount().then((result) => {
  console.log(result.code);
});

2. transform jsx file

//transform jsx format file content:
const jsxCode = `

const Component = ({ title, count }) => {
  return <div><h1>{title}</h1><p>{count}</p></div>;
};
`;

const output = transformSync(jsxCode, {
  module: { type: "es6" },
  minify: false,
  sourceMaps: false,
  jsc: {
    parser: {
      syntax: "ecmascript",
      jsx: true,
      // tsx: true, // transform tsx
      minify: { compress: { unused: true } },
    },
    transform: {
      react: {
        runtime: "classic", //"automatic" | "classic" | "preserve"
        pragma: "React.createElement",
        pragmaFrag: "React.Fragment",
      },
    },
    target: "es2020",
  },
  module: {
    type: "commonjs",
  },
}).code;

3. 基础压缩

const result = await transform(code, {
  minify: true, // 简单启用压缩
  jsc: {
    parser: { syntax: "ecmascript", jsx: true },
    target: "es5",
  },
});

4. 详细压缩配置

const result = await transform(code, {
  jsc: {
    parser: { syntax: "ecmascript", jsx: true },
    minify: {
      compress: {
        unused: true, // 删除未使用的变量
        dead_code: true, // 删除死代码
        drop_console: true, // 删除 console.*
        drop_debugger: true, // 删除 debugger
        collapse_vars: true, // 内联变量
        evaluate: true, // 求值常量表达式
        if_return: true, // 优化 if/return
        join_vars: true, // 合并 var 声明
        loops: true, // 优化循环
        reduce_vars: true, // 优化重复变量
        side_effects: true, // 删除无副作用代码
        switches: true, // 优化 switch
        typeofs: true, // 优化 typeof
        booleans: true, // 优化布尔值
        conditionals: true, // 优化条件语句
        properties: true, // 优化属性访问
        keep_fargs: true, // 保持函数参数
        keep_fnames: false, // 不保持函数名
        keep_classnames: false, // 不保持类名
      },
      mangle: {
        toplevel: true, // 混淆顶层作用域
        keep_classnames: false, // 不保持类名
        keep_fnames: false, // 不保持函数名
        keep_private_props: false, // 不保持私有属性
        safari10: false, // Safari 10 兼容
      },
      format: {
        comments: false, // 删除注释
        beautify: false, // 不美化
        braces: false, // 不总是使用大括号
      },
    },
    target: "es5",
  },
  minify: true,
});

reference