@boperators/plugin-vite 0.1.4 → 0.2.1

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.
Files changed (2) hide show
  1. package/README.md +63 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @boperators/plugin-vite
2
+
3
+ ![Sym.JS logo](https://github.com/DiefBell/boperators/blob/653ea138f4dcd1e6b4dd112133a4942f70e91fb3/logo.png)
4
+
5
+ Vite plugin for [boperators](https://www.npmjs.com/package/boperators) that transforms operator overloads during the Vite build and during HMR. Runs as an `enforce: "pre"` plugin before TypeScript compilation, replacing operator expressions with function calls and generating V3 source maps.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ npm install -D boperators @boperators/plugin-vite
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ Add the plugin to your `vite.config.ts`:
16
+
17
+ ```typescript
18
+ import { boperators } from "@boperators/plugin-vite";
19
+ import { defineConfig } from "vite";
20
+
21
+ export default defineConfig({
22
+ plugins: [boperators()],
23
+ });
24
+ ```
25
+
26
+ The plugin runs with `enforce: "pre"` to ensure boperators transforms your source before Vite's TypeScript handling.
27
+
28
+ ### Options
29
+
30
+ | Option | Type | Default | Description |
31
+ |--------|------|---------|-------------|
32
+ | `project` | `string` | `"tsconfig.json"` | Path to `tsconfig.json`, relative to Vite's root |
33
+ | `include` | `RegExp` | `/\.tsx?$/` | File filter — only matching files are transformed |
34
+
35
+ Options are passed to the plugin factory:
36
+
37
+ ```typescript
38
+ boperators({
39
+ project: "./tsconfig.build.json",
40
+ })
41
+ ```
42
+
43
+ ## How It Works
44
+
45
+ The plugin initialises once when Vite resolves its config, then transforms files on demand:
46
+
47
+ 1. `configResolved` — creates a [ts-morph](https://ts-morph.com) Project from your tsconfig and scans all source files for operator overload definitions
48
+ 2. `transform` — for each `.ts`/`.tsx` file, syncs ts-morph's in-memory state with the current file content (so HMR edits are picked up without restarting), then replaces operator expressions (e.g. `v1 + v2` becomes `Vector3["+"][0](v1, v2)`) and returns a V3 source map so breakpoints and stack traces map back to the original source
49
+
50
+ ## Comparison with Other Approaches
51
+
52
+ | Approach | When it runs | Use case |
53
+ |----------|-------------|----------|
54
+ | **`@boperators/cli`** | Before compilation | Batch transform to disk, then compile normally |
55
+ | **`@boperators/plugin-tsc`** | During compilation | Seamless `tsc` integration, no intermediate files |
56
+ | **`@boperators/webpack-loader`** | During bundling | Webpack projects, integrates into existing build pipeline |
57
+ | **`@boperators/plugin-vite`** | During bundling | Vite projects, integrates into Rollup-based pipeline |
58
+ | **`@boperators/plugin-esbuild`** | During bundling | ESBuild projects, fast bundler integration |
59
+ | **`@boperators/plugin-bun`** | At runtime | Bun-only, transforms on module load |
60
+
61
+ ## License
62
+
63
+ MIT
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@boperators/plugin-vite",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "Vite plugin for boperators - transforms operator overloads at build time.",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/DiefBell/boperators",
8
+ "url": "git+https://github.com/DiefBell/boperators.git",
9
9
  "directory": "plugins/vite"
10
10
  },
11
11
  "bugs": {
@@ -39,7 +39,7 @@
39
39
  "dist"
40
40
  ],
41
41
  "peerDependencies": {
42
- "boperators": "0.1.4",
42
+ "boperators": "0.2.1",
43
43
  "typescript": ">=5.0.0 <5.10.0",
44
44
  "vite": ">=4.0.0"
45
45
  },