@swwind/treeshake-events
v2.1.3
Published
Remove specific properties from generated jsx function calls.
Downloads
1
Readme
@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
jsx
function must use import statement and listed inoptions.jsxs
jsx
function can be renamed to other idents (doesn't matter our trackings)- first argument of
jsx
is string literal and second is object literal. - 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.