2.1.3 • Published 1 year ago

@swwind/treeshake-events v2.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@swwind/treeshake-events

Remove specific properties from generated jsx function calls.

Before

import { jsx as _jsx } from "preact/jsx-runtime";

_jsx("div", { id: "app", onClick: () => alert(2333) });

After

import { jsx as _jsx } from "preact/jsx-runtime";

_jsx("div", { id: "app" });

Note: the treeshake only works when

  1. jsx function must use import statement and listed in options.jsxs
  2. jsx function can be renamed to other idents (doesn't matter our trackings)
  3. first argument of jsx is string literal and second is object literal.
  4. property name must be ident or string (no { ["onClick"]: () => {} } please)

If all the conditions are true, a treeshake of that property will be performed.

Usage

import treeshakeEvents from "@swwind/treeshake-events";

interface PluginOptions {
  // jsx function names
  jsxs?: string[]; // defaults ['jsx', 'jsxs', 'jsxDEV']
  // event properties regex
  matches?: string[]; // defaults ['^on[A-Z]']
}

jsc: {
  // ...
  experimental: {
    plugins: [
      treeshakeEvents(options),
    ];
  }
}

Note: this plugin does not support use module name directly.

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago