vite-plugin-solid-oxc 0.1.0-alpha.5

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.
@@ -0,0 +1,70 @@
1
+ import { FilterPattern, Plugin } from 'vite';
2
+ export { Plugin } from 'vite';
3
+
4
+ interface SolidOxcOptions {
5
+ /**
6
+ * Filter which files to transform
7
+ * @default /\.[jt]sx$/
8
+ */
9
+ include?: FilterPattern;
10
+ /**
11
+ * Filter which files to exclude
12
+ * @default /node_modules/
13
+ */
14
+ exclude?: FilterPattern;
15
+ /**
16
+ * The module to import runtime helpers from
17
+ * @default 'solid-js/web'
18
+ */
19
+ module_name?: string;
20
+ /**
21
+ * Generate mode
22
+ * @default 'dom'
23
+ */
24
+ generate?: 'dom' | 'ssr' | 'universal';
25
+ /**
26
+ * Enable hydration support
27
+ * @default false
28
+ */
29
+ hydratable?: boolean;
30
+ /**
31
+ * Delegate events for better performance
32
+ * @default true
33
+ */
34
+ delegate_events?: boolean;
35
+ /**
36
+ * Wrap conditionals in memos
37
+ * @default true
38
+ */
39
+ wrap_conditionals?: boolean;
40
+ /**
41
+ * Pass context to custom elements
42
+ * @default true
43
+ */
44
+ context_to_custom_elements?: boolean;
45
+ /**
46
+ * Built-in components that should be passed through
47
+ */
48
+ builtIns?: string[];
49
+ /**
50
+ * Enable SSR mode (shorthand for generate: 'ssr')
51
+ * @default false
52
+ */
53
+ ssr?: boolean;
54
+ /**
55
+ * Dev mode - enables additional debugging
56
+ * @default based on vite mode
57
+ */
58
+ dev?: boolean;
59
+ /**
60
+ * Hot module replacement
61
+ * @default true in dev mode
62
+ */
63
+ hot?: boolean;
64
+ }
65
+ /**
66
+ * Vite plugin for SolidJS using OXC-based compiler
67
+ */
68
+ declare function solidOxc(options?: SolidOxcOptions): Plugin;
69
+
70
+ export { type SolidOxcOptions, solidOxc as default, solidOxc };
@@ -0,0 +1,70 @@
1
+ import { FilterPattern, Plugin } from 'vite';
2
+ export { Plugin } from 'vite';
3
+
4
+ interface SolidOxcOptions {
5
+ /**
6
+ * Filter which files to transform
7
+ * @default /\.[jt]sx$/
8
+ */
9
+ include?: FilterPattern;
10
+ /**
11
+ * Filter which files to exclude
12
+ * @default /node_modules/
13
+ */
14
+ exclude?: FilterPattern;
15
+ /**
16
+ * The module to import runtime helpers from
17
+ * @default 'solid-js/web'
18
+ */
19
+ module_name?: string;
20
+ /**
21
+ * Generate mode
22
+ * @default 'dom'
23
+ */
24
+ generate?: 'dom' | 'ssr' | 'universal';
25
+ /**
26
+ * Enable hydration support
27
+ * @default false
28
+ */
29
+ hydratable?: boolean;
30
+ /**
31
+ * Delegate events for better performance
32
+ * @default true
33
+ */
34
+ delegate_events?: boolean;
35
+ /**
36
+ * Wrap conditionals in memos
37
+ * @default true
38
+ */
39
+ wrap_conditionals?: boolean;
40
+ /**
41
+ * Pass context to custom elements
42
+ * @default true
43
+ */
44
+ context_to_custom_elements?: boolean;
45
+ /**
46
+ * Built-in components that should be passed through
47
+ */
48
+ builtIns?: string[];
49
+ /**
50
+ * Enable SSR mode (shorthand for generate: 'ssr')
51
+ * @default false
52
+ */
53
+ ssr?: boolean;
54
+ /**
55
+ * Dev mode - enables additional debugging
56
+ * @default based on vite mode
57
+ */
58
+ dev?: boolean;
59
+ /**
60
+ * Hot module replacement
61
+ * @default true in dev mode
62
+ */
63
+ hot?: boolean;
64
+ }
65
+ /**
66
+ * Vite plugin for SolidJS using OXC-based compiler
67
+ */
68
+ declare function solidOxc(options?: SolidOxcOptions): Plugin;
69
+
70
+ export { type SolidOxcOptions, solidOxc as default, solidOxc };
package/dist/index.js ADDED
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => solidOxc,
34
+ solidOxc: () => solidOxc
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var import_vite = require("vite");
38
+ var import_path = require("path");
39
+ var import_fs = require("fs");
40
+ var isVite6 = +import_vite.version.split(".")[0] >= 6;
41
+ var SOLID_PACKAGES_WITH_JSX = {
42
+ "solid-markdown": "dist/dev.js"
43
+ };
44
+ var defaultOptions = {
45
+ include: /\.[jt]sx$/,
46
+ exclude: /node_modules/,
47
+ module_name: "solid-js/web",
48
+ generate: "dom",
49
+ hydratable: false,
50
+ delegate_events: true,
51
+ wrap_conditionals: true,
52
+ context_to_custom_elements: true,
53
+ builtIns: [
54
+ "For",
55
+ "Show",
56
+ "Switch",
57
+ "Match",
58
+ "Suspense",
59
+ "SuspenseList",
60
+ "Portal",
61
+ "Index",
62
+ "Dynamic",
63
+ "ErrorBoundary"
64
+ ]
65
+ };
66
+ function solidOxc(options = {}) {
67
+ const opts = { ...defaultOptions, ...options };
68
+ const filter = (0, import_vite.createFilter)(opts.include, opts.exclude);
69
+ let isDev = false;
70
+ let isSSR = false;
71
+ let replaceDev = false;
72
+ let solidJsxOxc = null;
73
+ return {
74
+ name: "vite-plugin-solid-oxc",
75
+ enforce: "pre",
76
+ config(_userConfig, env) {
77
+ replaceDev = env.command === "serve";
78
+ const resolveConfig = {
79
+ dedupe: ["solid-js", "solid-js/web"]
80
+ };
81
+ if (!isVite6) {
82
+ resolveConfig.conditions = ["solid", ...replaceDev ? ["development"] : []];
83
+ }
84
+ return {
85
+ esbuild: {
86
+ // Let our plugin handle JSX, not esbuild
87
+ jsx: "preserve",
88
+ jsxImportSource: "solid-js"
89
+ },
90
+ resolve: resolveConfig
91
+ };
92
+ },
93
+ // @ts-ignore This hook only works in Vite 6+
94
+ async configEnvironment(name, config, env) {
95
+ if (!isVite6) {
96
+ return;
97
+ }
98
+ config.resolve ?? (config.resolve = {});
99
+ if (config.resolve.conditions == null) {
100
+ const { defaultClientConditions, defaultServerConditions } = await import("vite");
101
+ if (config.consumer === "client" || name === "client" || env.isSsrTargetWebworker) {
102
+ config.resolve.conditions = [...defaultClientConditions];
103
+ } else {
104
+ config.resolve.conditions = [...defaultServerConditions];
105
+ }
106
+ }
107
+ const extraConditions = ["solid", ...replaceDev ? ["development"] : []];
108
+ const currentConditions = config.resolve.conditions;
109
+ const prepend = [];
110
+ for (const condition of extraConditions) {
111
+ if (!currentConditions.includes(condition)) {
112
+ prepend.push(condition);
113
+ }
114
+ }
115
+ config.resolve.conditions = [...prepend, ...currentConditions];
116
+ const dedupe = Array.isArray(config.resolve.dedupe) ? config.resolve.dedupe : [];
117
+ const nextDedupe = [...dedupe];
118
+ for (const pkg of ["solid-js", "solid-js/web"]) {
119
+ if (!nextDedupe.includes(pkg)) {
120
+ nextDedupe.push(pkg);
121
+ }
122
+ }
123
+ config.resolve.dedupe = nextDedupe;
124
+ },
125
+ configResolved(config) {
126
+ isDev = config.command === "serve";
127
+ isSSR = opts.ssr ?? (typeof config.build?.ssr === "boolean" ? config.build.ssr : !!config.build?.ssr);
128
+ },
129
+ resolveId(source, importer) {
130
+ const redirect = SOLID_PACKAGES_WITH_JSX[source];
131
+ if (redirect && importer && !importer.includes("node_modules/.vite")) {
132
+ try {
133
+ let dir = (0, import_path.dirname)(importer);
134
+ while (dir !== "/") {
135
+ const nmPath = (0, import_path.resolve)(dir, "node_modules", source, "package.json");
136
+ if ((0, import_fs.existsSync)(nmPath)) {
137
+ const pkgDir = (0, import_path.dirname)(nmPath);
138
+ const targetPath = (0, import_path.resolve)(pkgDir, redirect);
139
+ if ((0, import_fs.existsSync)(targetPath)) {
140
+ return targetPath;
141
+ }
142
+ }
143
+ dir = (0, import_path.dirname)(dir);
144
+ }
145
+ } catch {
146
+ }
147
+ }
148
+ return null;
149
+ },
150
+ async buildStart() {
151
+ try {
152
+ solidJsxOxc = await import("solid-jsx-oxc");
153
+ } catch (e) {
154
+ this.error(
155
+ "Failed to load solid-jsx-oxc. Make sure it is built for your platform.\\nRun: cd packages/solid-jsx-oxc && npm run build"
156
+ );
157
+ }
158
+ },
159
+ async transform(code, id) {
160
+ const fileId = id.split("?", 1)[0];
161
+ if (!filter(fileId)) {
162
+ return null;
163
+ }
164
+ if (!solidJsxOxc) {
165
+ this.error("solid-jsx-oxc module not loaded");
166
+ return null;
167
+ }
168
+ const generate = isSSR ? "ssr" : opts.generate;
169
+ try {
170
+ const result = solidJsxOxc.transformJsx(code, {
171
+ filename: fileId,
172
+ module_name: opts.module_name,
173
+ generate,
174
+ hydratable: opts.hydratable,
175
+ delegate_events: opts.delegate_events,
176
+ wrap_conditionals: opts.wrap_conditionals,
177
+ context_to_custom_elements: opts.context_to_custom_elements,
178
+ source_map: true
179
+ });
180
+ if (isDev && opts.hot !== false) {
181
+ const hotCode = `
182
+ if (import.meta.hot) {
183
+ import.meta.hot.accept();
184
+ }
185
+ `;
186
+ result.code = result.code + hotCode;
187
+ }
188
+ return {
189
+ code: result.code,
190
+ map: result.map ? JSON.parse(result.map) : null
191
+ };
192
+ } catch (e) {
193
+ const message = e instanceof Error ? e.message : String(e);
194
+ this.error(`Failed to transform ${id}: ${message}`);
195
+ return null;
196
+ }
197
+ }
198
+ };
199
+ }
200
+ // Annotate the CommonJS export names for ESM import in node:
201
+ 0 && (module.exports = {
202
+ solidOxc
203
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,168 @@
1
+ // src/index.ts
2
+ import { createFilter, version } from "vite";
3
+ import { resolve, dirname } from "path";
4
+ import { existsSync } from "fs";
5
+ var isVite6 = +version.split(".")[0] >= 6;
6
+ var SOLID_PACKAGES_WITH_JSX = {
7
+ "solid-markdown": "dist/dev.js"
8
+ };
9
+ var defaultOptions = {
10
+ include: /\.[jt]sx$/,
11
+ exclude: /node_modules/,
12
+ module_name: "solid-js/web",
13
+ generate: "dom",
14
+ hydratable: false,
15
+ delegate_events: true,
16
+ wrap_conditionals: true,
17
+ context_to_custom_elements: true,
18
+ builtIns: [
19
+ "For",
20
+ "Show",
21
+ "Switch",
22
+ "Match",
23
+ "Suspense",
24
+ "SuspenseList",
25
+ "Portal",
26
+ "Index",
27
+ "Dynamic",
28
+ "ErrorBoundary"
29
+ ]
30
+ };
31
+ function solidOxc(options = {}) {
32
+ const opts = { ...defaultOptions, ...options };
33
+ const filter = createFilter(opts.include, opts.exclude);
34
+ let isDev = false;
35
+ let isSSR = false;
36
+ let replaceDev = false;
37
+ let solidJsxOxc = null;
38
+ return {
39
+ name: "vite-plugin-solid-oxc",
40
+ enforce: "pre",
41
+ config(_userConfig, env) {
42
+ replaceDev = env.command === "serve";
43
+ const resolveConfig = {
44
+ dedupe: ["solid-js", "solid-js/web"]
45
+ };
46
+ if (!isVite6) {
47
+ resolveConfig.conditions = ["solid", ...replaceDev ? ["development"] : []];
48
+ }
49
+ return {
50
+ esbuild: {
51
+ // Let our plugin handle JSX, not esbuild
52
+ jsx: "preserve",
53
+ jsxImportSource: "solid-js"
54
+ },
55
+ resolve: resolveConfig
56
+ };
57
+ },
58
+ // @ts-ignore This hook only works in Vite 6+
59
+ async configEnvironment(name, config, env) {
60
+ if (!isVite6) {
61
+ return;
62
+ }
63
+ config.resolve ?? (config.resolve = {});
64
+ if (config.resolve.conditions == null) {
65
+ const { defaultClientConditions, defaultServerConditions } = await import("vite");
66
+ if (config.consumer === "client" || name === "client" || env.isSsrTargetWebworker) {
67
+ config.resolve.conditions = [...defaultClientConditions];
68
+ } else {
69
+ config.resolve.conditions = [...defaultServerConditions];
70
+ }
71
+ }
72
+ const extraConditions = ["solid", ...replaceDev ? ["development"] : []];
73
+ const currentConditions = config.resolve.conditions;
74
+ const prepend = [];
75
+ for (const condition of extraConditions) {
76
+ if (!currentConditions.includes(condition)) {
77
+ prepend.push(condition);
78
+ }
79
+ }
80
+ config.resolve.conditions = [...prepend, ...currentConditions];
81
+ const dedupe = Array.isArray(config.resolve.dedupe) ? config.resolve.dedupe : [];
82
+ const nextDedupe = [...dedupe];
83
+ for (const pkg of ["solid-js", "solid-js/web"]) {
84
+ if (!nextDedupe.includes(pkg)) {
85
+ nextDedupe.push(pkg);
86
+ }
87
+ }
88
+ config.resolve.dedupe = nextDedupe;
89
+ },
90
+ configResolved(config) {
91
+ isDev = config.command === "serve";
92
+ isSSR = opts.ssr ?? (typeof config.build?.ssr === "boolean" ? config.build.ssr : !!config.build?.ssr);
93
+ },
94
+ resolveId(source, importer) {
95
+ const redirect = SOLID_PACKAGES_WITH_JSX[source];
96
+ if (redirect && importer && !importer.includes("node_modules/.vite")) {
97
+ try {
98
+ let dir = dirname(importer);
99
+ while (dir !== "/") {
100
+ const nmPath = resolve(dir, "node_modules", source, "package.json");
101
+ if (existsSync(nmPath)) {
102
+ const pkgDir = dirname(nmPath);
103
+ const targetPath = resolve(pkgDir, redirect);
104
+ if (existsSync(targetPath)) {
105
+ return targetPath;
106
+ }
107
+ }
108
+ dir = dirname(dir);
109
+ }
110
+ } catch {
111
+ }
112
+ }
113
+ return null;
114
+ },
115
+ async buildStart() {
116
+ try {
117
+ solidJsxOxc = await import("solid-jsx-oxc");
118
+ } catch (e) {
119
+ this.error(
120
+ "Failed to load solid-jsx-oxc. Make sure it is built for your platform.\\nRun: cd packages/solid-jsx-oxc && npm run build"
121
+ );
122
+ }
123
+ },
124
+ async transform(code, id) {
125
+ const fileId = id.split("?", 1)[0];
126
+ if (!filter(fileId)) {
127
+ return null;
128
+ }
129
+ if (!solidJsxOxc) {
130
+ this.error("solid-jsx-oxc module not loaded");
131
+ return null;
132
+ }
133
+ const generate = isSSR ? "ssr" : opts.generate;
134
+ try {
135
+ const result = solidJsxOxc.transformJsx(code, {
136
+ filename: fileId,
137
+ module_name: opts.module_name,
138
+ generate,
139
+ hydratable: opts.hydratable,
140
+ delegate_events: opts.delegate_events,
141
+ wrap_conditionals: opts.wrap_conditionals,
142
+ context_to_custom_elements: opts.context_to_custom_elements,
143
+ source_map: true
144
+ });
145
+ if (isDev && opts.hot !== false) {
146
+ const hotCode = `
147
+ if (import.meta.hot) {
148
+ import.meta.hot.accept();
149
+ }
150
+ `;
151
+ result.code = result.code + hotCode;
152
+ }
153
+ return {
154
+ code: result.code,
155
+ map: result.map ? JSON.parse(result.map) : null
156
+ };
157
+ } catch (e) {
158
+ const message = e instanceof Error ? e.message : String(e);
159
+ this.error(`Failed to transform ${id}: ${message}`);
160
+ return null;
161
+ }
162
+ }
163
+ };
164
+ }
165
+ export {
166
+ solidOxc as default,
167
+ solidOxc
168
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "vite-plugin-solid-oxc",
3
+ "version": "0.1.0-alpha.5",
4
+ "description": "Vite plugin for SolidJS using OXC-based compiler",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
21
+ },
22
+ "keywords": [
23
+ "vite",
24
+ "vite-plugin",
25
+ "solid",
26
+ "solidjs",
27
+ "jsx",
28
+ "oxc",
29
+ "rolldown"
30
+ ],
31
+ "author": "SolidJS Contributors",
32
+ "license": "MIT",
33
+ "peerDependencies": {
34
+ "solid-jsx-oxc": "*",
35
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.0.0",
39
+ "tsup": "^8.5.1",
40
+ "typescript": "^5.0.0",
41
+ "vite": "^6.0.0"
42
+ }
43
+ }