preact-alchemy 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,16 @@
1
- import { Plugin } from 'vite';
1
+ import * as magic_string from 'magic-string';
2
2
 
3
- declare function preactAlchemy(): Plugin;
3
+ type PreactAlchemyOptions = {
4
+ include?: RegExp;
5
+ exclude?: RegExp;
6
+ };
7
+ declare function preactAlchemy(options?: PreactAlchemyOptions): {
8
+ name: string;
9
+ enforce: "post";
10
+ transform(this: unknown, code: string, id: string): {
11
+ code: string;
12
+ map: magic_string.SourceMap | null;
13
+ } | null;
14
+ };
4
15
 
5
- export { preactAlchemy as default };
16
+ export { type PreactAlchemyOptions, preactAlchemy as default };
package/dist/vite.js CHANGED
@@ -3,16 +3,19 @@ import {
3
3
  } from "./chunk-JSNOUUYJ.js";
4
4
 
5
5
  // src/vite.ts
6
- var defaultInclude = /\.(?:mjs|cjs|js|jsx|mts|cts|ts|tsx)$/;
7
- function preactAlchemy() {
6
+ function preactAlchemy(options = {}) {
7
+ const {
8
+ include = /\.(?:mjs|cjs|js|jsx|mts|cts|ts|tsx)$/,
9
+ exclude = /node_modules/
10
+ } = options;
8
11
  return {
9
12
  name: "preact-alchemy",
10
13
  enforce: "post",
11
14
  transform(code, id) {
12
15
  if (id.startsWith("\0")) return null;
13
16
  const cleanId = id.split("?")[0];
14
- if (!defaultInclude.test(cleanId)) return null;
15
- if (cleanId.includes("node_modules")) return null;
17
+ if (!include.test(cleanId)) return null;
18
+ if (exclude.test(cleanId)) return null;
16
19
  if (!code.includes("use alchemy")) return null;
17
20
  const result = transform(code, cleanId);
18
21
  if (result.code === code) return null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "preact-alchemy",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.2.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
package/readme.md CHANGED
@@ -100,7 +100,7 @@ b = __alchemy_signal(b)
100
100
 
101
101
  ## Vite plugin
102
102
 
103
- Use the built-in Vite plugin for zero-config integration:
103
+ Our Vite plugin should work with Vite, Rolldown, and Rollup. You don't need Vite installed to use it.
104
104
 
105
105
  ```ts
106
106
  // vite.config.ts
@@ -119,6 +119,45 @@ The plugin:
119
119
  - Skips files in `node_modules`.
120
120
  - Only transforms files that include the `"use alchemy"` directive.
121
121
 
122
+ ## Esbuild plugin
123
+
124
+ Use the built-in esbuild plugin when you want to integrate with esbuild or tools
125
+ built on top of it:
126
+
127
+ ```sh
128
+ pnpm add @preact-alchemy/esbuild-plugin
129
+ ```
130
+
131
+ ```ts
132
+ import { build } from 'esbuild'
133
+ import preactAlchemy from '@preact-alchemy/esbuild-plugin'
134
+
135
+ await build({
136
+ entryPoints: ['src/index.tsx'],
137
+ bundle: true,
138
+ plugins: [preactAlchemy()],
139
+ })
140
+ ```
141
+
142
+ The plugin:
143
+
144
+ - Runs after TypeScript/JSX are compiled to JavaScript (via `onTransform`).
145
+ - Applies to `.js/.jsx/.mjs/.cjs/.ts/.tsx/.mts/.cts` files.
146
+ - Skips files in `node_modules` by default.
147
+ - Only transforms files that include the `"use alchemy"` directive.
148
+
149
+ ### Options
150
+
151
+ ```ts
152
+ type PreactAlchemyEsbuildOptions = {
153
+ include?: RegExp
154
+ exclude?: RegExp
155
+ }
156
+ ```
157
+
158
+ - `include`: RegExp to opt into files (defaults to common JS/TS extensions).
159
+ - `exclude`: RegExp to skip files (defaults to `/node_modules/`).
160
+
122
161
  ## Programmatic API
123
162
 
124
163
  ```ts