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

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,68 @@
1
+ import type { Plugin, FilterPattern } from 'vite';
2
+ export interface SolidOxcOptions {
3
+ /**
4
+ * Filter which files to transform
5
+ * @default /\.[jt]sx$/
6
+ */
7
+ include?: FilterPattern;
8
+ /**
9
+ * Filter which files to exclude
10
+ * @default /node_modules/
11
+ */
12
+ exclude?: FilterPattern;
13
+ /**
14
+ * The module to import runtime helpers from
15
+ * @default 'solid-js/web'
16
+ */
17
+ module_name?: string;
18
+ /**
19
+ * Generate mode
20
+ * @default 'dom'
21
+ */
22
+ generate?: 'dom' | 'ssr' | 'universal';
23
+ /**
24
+ * Enable hydration support
25
+ * @default false
26
+ */
27
+ hydratable?: boolean;
28
+ /**
29
+ * Delegate events for better performance
30
+ * @default true
31
+ */
32
+ delegate_events?: boolean;
33
+ /**
34
+ * Wrap conditionals in memos
35
+ * @default true
36
+ */
37
+ wrap_conditionals?: boolean;
38
+ /**
39
+ * Pass context to custom elements
40
+ * @default true
41
+ */
42
+ context_to_custom_elements?: boolean;
43
+ /**
44
+ * Built-in components that should be passed through
45
+ */
46
+ builtIns?: string[];
47
+ /**
48
+ * Enable SSR mode (shorthand for generate: 'ssr')
49
+ * @default false
50
+ */
51
+ ssr?: boolean;
52
+ /**
53
+ * Dev mode - enables additional debugging
54
+ * @default based on vite mode
55
+ */
56
+ dev?: boolean;
57
+ /**
58
+ * Hot module replacement
59
+ * @default true in dev mode
60
+ */
61
+ hot?: boolean;
62
+ }
63
+ /**
64
+ * Vite plugin for SolidJS using OXC-based compiler
65
+ */
66
+ export default function solidOxc(options?: SolidOxcOptions): Plugin;
67
+ export { solidOxc };
68
+ export type { Plugin };
package/dist/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { createFilter } from 'vite';
2
+ const defaultOptions = {
3
+ include: /\.[jt]sx$/,
4
+ exclude: /node_modules/,
5
+ module_name: 'solid-js/web',
6
+ generate: 'dom',
7
+ hydratable: false,
8
+ delegate_events: true,
9
+ wrap_conditionals: true,
10
+ context_to_custom_elements: true,
11
+ builtIns: [
12
+ 'For',
13
+ 'Show',
14
+ 'Switch',
15
+ 'Match',
16
+ 'Suspense',
17
+ 'SuspenseList',
18
+ 'Portal',
19
+ 'Index',
20
+ 'Dynamic',
21
+ 'ErrorBoundary',
22
+ ],
23
+ };
24
+ /**
25
+ * Vite plugin for SolidJS using OXC-based compiler
26
+ */
27
+ export default function solidOxc(options = {}) {
28
+ const opts = { ...defaultOptions, ...options };
29
+ const filter = createFilter(opts.include, opts.exclude);
30
+ let isDev = false;
31
+ let isSSR = false;
32
+ // Lazy load the native module
33
+ let solidJsxOxc = null;
34
+ return {
35
+ name: 'vite-plugin-solid-oxc',
36
+ enforce: 'pre',
37
+ configResolved(config) {
38
+ isDev = config.command === 'serve';
39
+ isSSR = opts.ssr ?? (typeof config.build?.ssr === 'boolean' ? config.build.ssr : !!config.build?.ssr);
40
+ },
41
+ async buildStart() {
42
+ // Load the native module
43
+ try {
44
+ solidJsxOxc = await import('solid-jsx-oxc');
45
+ }
46
+ catch (e) {
47
+ this.error('Failed to load solid-jsx-oxc. Make sure it is built for your platform.\n' +
48
+ 'Run: cd packages/solid-jsx-oxc && npm run build');
49
+ }
50
+ },
51
+ async transform(code, id) {
52
+ const fileId = id.split('?', 1)[0];
53
+ if (!filter(fileId)) {
54
+ return null;
55
+ }
56
+ if (!solidJsxOxc) {
57
+ this.error('solid-jsx-oxc module not loaded');
58
+ return null;
59
+ }
60
+ const generate = isSSR ? 'ssr' : opts.generate;
61
+ try {
62
+ const result = solidJsxOxc.transformJsx(code, {
63
+ filename: fileId,
64
+ moduleName: opts.module_name,
65
+ generate,
66
+ hydratable: opts.hydratable,
67
+ delegateEvents: opts.delegate_events,
68
+ wrapConditionals: opts.wrap_conditionals,
69
+ contextToCustomElements: opts.context_to_custom_elements,
70
+ sourceMap: true,
71
+ });
72
+ // Add HMR support in dev mode
73
+ if (isDev && opts.hot !== false) {
74
+ const hotCode = `
75
+ if (import.meta.hot) {
76
+ import.meta.hot.accept();
77
+ }
78
+ `;
79
+ result.code = result.code + hotCode;
80
+ }
81
+ return {
82
+ code: result.code,
83
+ map: result.map ? JSON.parse(result.map) : null,
84
+ };
85
+ }
86
+ catch (e) {
87
+ const message = e instanceof Error ? e.message : String(e);
88
+ this.error(`Failed to transform ${id}: ${message}`);
89
+ return null;
90
+ }
91
+ },
92
+ // Handle Solid's JSX types
93
+ config() {
94
+ return {
95
+ esbuild: {
96
+ // Let our plugin handle JSX, not esbuild
97
+ jsx: 'preserve',
98
+ jsxImportSource: 'solid-js',
99
+ },
100
+ resolve: {
101
+ conditions: ['solid'],
102
+ dedupe: ['solid-js', 'solid-js/web'],
103
+ },
104
+ };
105
+ },
106
+ };
107
+ }
108
+ // Named export for compatibility
109
+ export { solidOxc };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "vite-plugin-solid-oxc",
3
+ "version": "0.1.0-alpha.10",
4
+ "description": "Vite plugin for SolidJS using OXC-based compiler",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json",
20
+ "dev": "tsc -p tsconfig.json -w"
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
+ "typescript": "^5.0.0",
40
+ "vite": "^6.0.0"
41
+ }
42
+ }