@fukict/vite-plugin 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Fukict Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # @fukict/vite-plugin
2
+
3
+ Official Vite plugin for Fukict framework.
4
+
5
+ ## Features
6
+
7
+ - ✅ Zero-config setup
8
+ - ✅ TypeScript support (built-in)
9
+ - ✅ Auto component wrapping with `defineFukict`
10
+ - ✅ JSX to hyperscript transformation
11
+ - ✅ Development mode enhancements
12
+ - ✅ Source map support
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pnpm add -D @fukict/vite-plugin
18
+ pnpm add @fukict/basic
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Basic Setup
24
+
25
+ **vite.config.ts**:
26
+
27
+ ```typescript
28
+ import fukict from '@fukict/vite-plugin';
29
+
30
+ import { defineConfig } from 'vite';
31
+
32
+ export default defineConfig({
33
+ plugins: [fukict()],
34
+ });
35
+ ```
36
+
37
+ That's it! The plugin will automatically:
38
+
39
+ 1. Transform JSX to `hyperscript()` calls
40
+ 2. Auto-wrap components with `defineFukict()`
41
+ 3. Handle TypeScript syntax
42
+ 4. Inject `displayName` in development mode
43
+
44
+ ### With Options
45
+
46
+ ```typescript
47
+ import fukict from '@fukict/vite-plugin';
48
+
49
+ import { defineConfig } from 'vite';
50
+
51
+ export default defineConfig({
52
+ plugins: [
53
+ fukict({
54
+ // Include patterns (default: /\.[jt]sx$/)
55
+ include: /\.[jt]sx$/,
56
+
57
+ // Exclude patterns (default: /node_modules/)
58
+ exclude: /node_modules/,
59
+
60
+ // Babel options
61
+ babel: {
62
+ // Development mode (default: NODE_ENV !== 'production')
63
+ development: true,
64
+
65
+ // TypeScript support (default: true)
66
+ typescript: true,
67
+ },
68
+ }),
69
+ ],
70
+ });
71
+ ```
72
+
73
+ ## Options
74
+
75
+ ### `include`
76
+
77
+ **Type**: `RegExp | RegExp[]`
78
+ **Default**: `/\.[jt]sx$/`
79
+
80
+ Files to include for transformation.
81
+
82
+ **Example**:
83
+
84
+ ```typescript
85
+ fukict({
86
+ include: [/\.tsx$/, /\.jsx$/],
87
+ });
88
+ ```
89
+
90
+ ### `exclude`
91
+
92
+ **Type**: `RegExp | RegExp[]`
93
+ **Default**: `/node_modules/`
94
+
95
+ Files to exclude from transformation.
96
+
97
+ **Example**:
98
+
99
+ ```typescript
100
+ fukict({
101
+ exclude: [/node_modules/, /\.spec\.tsx$/],
102
+ });
103
+ ```
104
+
105
+ ### `babel.development`
106
+
107
+ **Type**: `boolean`
108
+ **Default**: `process.env.NODE_ENV !== 'production'`
109
+
110
+ Enable development mode features (like `displayName` injection).
111
+
112
+ ### `babel.typescript`
113
+
114
+ **Type**: `boolean`
115
+ **Default**: `true`
116
+
117
+ Enable TypeScript support.
118
+
119
+ ## How It Works
120
+
121
+ The plugin uses `@fukict/babel-preset` under the hood to transform your code:
122
+
123
+ ```tsx
124
+ // Input
125
+ const Greeting = ({ name }) => <div>Hello {name}</div>;
126
+
127
+ // Output
128
+ import { defineFukict, hyperscript } from '@fukict/basic';
129
+
130
+ const Greeting = defineFukict(({ name }) =>
131
+ hyperscript('div', null, ['Hello ', name])
132
+ );
133
+ Greeting.displayName = 'Greeting'; // in development mode
134
+ Greeting.__COMPONENT_TYPE__ = 'function';
135
+ ```
136
+
137
+ ## TypeScript Configuration
138
+
139
+ **tsconfig.json**:
140
+
141
+ ```json
142
+ {
143
+ "compilerOptions": {
144
+ "jsx": "preserve",
145
+ "jsxImportSource": "@fukict/basic"
146
+ }
147
+ }
148
+ ```
149
+
150
+ ## Examples
151
+
152
+ ### Basic Counter
153
+
154
+ ```tsx
155
+ // src/Counter.tsx
156
+ export const Counter = () => {
157
+ let count = 0;
158
+
159
+ const increment = () => {
160
+ count++;
161
+ // Re-render logic here
162
+ };
163
+
164
+ return (
165
+ <div>
166
+ <p>Count: {count}</p>
167
+ <button on:click={increment}>+</button>
168
+ </div>
169
+ );
170
+ };
171
+ ```
172
+
173
+ ### With Class Component
174
+
175
+ ```tsx
176
+ import { Fukict } from '@fukict/basic';
177
+
178
+ export class Timer extends Fukict<{}> {
179
+ private count = 0;
180
+ private timer?: number;
181
+
182
+ mounted() {
183
+ this.timer = setInterval(() => {
184
+ this.count++;
185
+ this.update(this.props);
186
+ }, 1000);
187
+ }
188
+
189
+ beforeUnmount() {
190
+ clearInterval(this.timer);
191
+ }
192
+
193
+ render() {
194
+ return <div>Timer: {this.count}</div>;
195
+ }
196
+ }
197
+ ```
198
+
199
+ ## FAQ
200
+
201
+ ### Q: Do I need to manually configure Babel?
202
+
203
+ **A**: No! The plugin automatically configures everything for you.
204
+
205
+ ### Q: Can I use this with other Vite plugins?
206
+
207
+ **A**: Yes, just add it to the `plugins` array along with other plugins.
208
+
209
+ ### Q: Does it work with TypeScript?
210
+
211
+ **A**: Yes, TypeScript support is built-in and enabled by default.
212
+
213
+ ### Q: How do I disable auto component wrapping?
214
+
215
+ **A**: Use the `@nofukict` comment:
216
+
217
+ ```tsx
218
+ /** @nofukict */
219
+ const MyFunction = () => <div />;
220
+ ```
221
+
222
+ ## Troubleshooting
223
+
224
+ ### JSX not transforming
225
+
226
+ **Check**:
227
+
228
+ 1. File extension is `.jsx` or `.tsx`
229
+ 2. `tsconfig.json` has `"jsx": "preserve"`
230
+ 3. Plugin is added to Vite config
231
+
232
+ ### TypeScript errors
233
+
234
+ **Check**:
235
+
236
+ 1. `@fukict/basic` is installed
237
+ 2. `jsxImportSource` is set to `"@fukict/basic"`
238
+ 3. TypeScript version >= 5.0.0
239
+
240
+ ## Related Packages
241
+
242
+ - **@fukict/basic** - Fukict runtime (required)
243
+ - **@fukict/babel-preset** - Babel preset (used internally)
244
+
245
+ ## License
246
+
247
+ MIT
@@ -0,0 +1,48 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Plugin options
4
+ */
5
+ export interface FukictPluginOptions {
6
+ /**
7
+ * Include patterns (minimatch)
8
+ * @default [/\.[jt]sx$/]
9
+ */
10
+ include?: RegExp | RegExp[];
11
+ /**
12
+ * Exclude patterns (minimatch)
13
+ * @default [/node_modules/]
14
+ */
15
+ exclude?: RegExp | RegExp[];
16
+ /**
17
+ * Babel preset options
18
+ */
19
+ babel?: {
20
+ /**
21
+ * Development mode
22
+ * @default process.env.NODE_ENV !== 'production'
23
+ */
24
+ development?: boolean;
25
+ /**
26
+ * Enable TypeScript support
27
+ * @default true
28
+ */
29
+ typescript?: boolean;
30
+ };
31
+ }
32
+ /**
33
+ * Fukict Vite Plugin
34
+ *
35
+ * Transforms JSX and TypeScript using @fukict/babel-preset
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { defineConfig } from 'vite';
40
+ * import fukict from '@fukict/vite-plugin';
41
+ *
42
+ * export default defineConfig({
43
+ * plugins: [fukict()],
44
+ * });
45
+ * ```
46
+ */
47
+ export default function fukict(options?: FukictPluginOptions): Plugin;
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;OAEG;IACH,KAAK,CAAC,EAAE;QACN;;;WAGG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;QAEtB;;;WAGG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC;CACH;AA4BD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CA2ExE"}
package/dist/index.js ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fukict/vite-plugin
3
+ *
4
+ * Vite plugin for Fukict framework
5
+ */
6
+ import { transformSync } from '@babel/core';
7
+ /**
8
+ * Default include patterns
9
+ */
10
+ var DEFAULT_INCLUDE = /\.[jt]sx$/;
11
+ /**
12
+ * Default exclude patterns
13
+ */
14
+ var DEFAULT_EXCLUDE = /node_modules/;
15
+ /**
16
+ * Check if file matches pattern
17
+ */
18
+ function matchPattern(id, patterns, defaultPattern) {
19
+ if (!patterns) {
20
+ return defaultPattern.test(id);
21
+ }
22
+ var patternList = Array.isArray(patterns) ? patterns : [patterns];
23
+ return patternList.some(function (pattern) { return pattern.test(id); });
24
+ }
25
+ /**
26
+ * Fukict Vite Plugin
27
+ *
28
+ * Transforms JSX and TypeScript using @fukict/babel-preset
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { defineConfig } from 'vite';
33
+ * import fukict from '@fukict/vite-plugin';
34
+ *
35
+ * export default defineConfig({
36
+ * plugins: [fukict()],
37
+ * });
38
+ * ```
39
+ */
40
+ export default function fukict(options) {
41
+ if (options === void 0) { options = {}; }
42
+ var _a = options.include, include = _a === void 0 ? DEFAULT_INCLUDE : _a, _b = options.exclude, exclude = _b === void 0 ? DEFAULT_EXCLUDE : _b, _c = options.babel, babel = _c === void 0 ? {} : _c;
43
+ var _d = babel.development, development = _d === void 0 ? process.env.NODE_ENV !== 'production' : _d, _e = babel.typescript, typescript = _e === void 0 ? true : _e;
44
+ return {
45
+ name: '@fukict/vite-plugin',
46
+ enforce: 'pre',
47
+ transform: function (code, id) {
48
+ // Check exclude patterns first
49
+ if (matchPattern(id, exclude, DEFAULT_EXCLUDE)) {
50
+ return null;
51
+ }
52
+ // Check include patterns
53
+ if (!matchPattern(id, include, DEFAULT_INCLUDE)) {
54
+ return null;
55
+ }
56
+ try {
57
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
58
+ var result = transformSync(code, {
59
+ presets: [
60
+ [
61
+ '@fukict/babel-preset',
62
+ {
63
+ development: development,
64
+ typescript: typescript,
65
+ },
66
+ ],
67
+ ],
68
+ filename: id,
69
+ sourceMaps: true,
70
+ configFile: false,
71
+ babelrc: false,
72
+ });
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
74
+ if (!result || !result.code) {
75
+ return null;
76
+ }
77
+ return {
78
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
79
+ code: result.code,
80
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
81
+ map: result.map,
82
+ };
83
+ }
84
+ catch (error) {
85
+ console.error("[fukict] Transform error in ".concat(id, ":"));
86
+ console.error(error);
87
+ this.error({
88
+ message: "Failed to transform ".concat(id, ": ").concat(error instanceof Error ? error.message : String(error)),
89
+ cause: error instanceof Error ? error : new Error(String(error)),
90
+ });
91
+ }
92
+ },
93
+ config: function () {
94
+ return {
95
+ esbuild: {
96
+ // Disable esbuild's JSX transform
97
+ jsx: 'preserve',
98
+ },
99
+ };
100
+ },
101
+ };
102
+ }
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsC5C;;GAEG;AACH,IAAM,eAAe,GAAG,WAAW,CAAC;AAEpC;;GAEG;AACH,IAAM,eAAe,GAAG,cAAc,CAAC;AAEvC;;GAEG;AACH,SAAS,YAAY,CACnB,EAAU,EACV,QAAuC,EACvC,cAAsB;IAEtB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,IAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpE,OAAO,WAAW,CAAC,IAAI,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAhB,CAAgB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAiC;IAAjC,wBAAA,EAAA,YAAiC;IAE5D,IAAA,KAGE,OAAO,QAHgB,EAAzB,OAAO,mBAAG,eAAe,KAAA,EACzB,KAEE,OAAO,QAFgB,EAAzB,OAAO,mBAAG,eAAe,KAAA,EACzB,KACE,OAAO,MADC,EAAV,KAAK,mBAAG,EAAE,KAAA,CACA;IAGV,IAAA,KAEE,KAAK,YAF4C,EAAnD,WAAW,mBAAG,OAAO,CAAC,GAAG,CAA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AK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAE;oBAC/F,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBACjE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,MAAM;YACJ,OAAO;gBACL,OAAO,EAAE;oBACP,kCAAkC;oBAClC,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@fukict/vite-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Fukict framework",
5
+ "keywords": [
6
+ "fukict",
7
+ "vite",
8
+ "plugin",
9
+ "jsx",
10
+ "typescript"
11
+ ],
12
+ "bugs": {
13
+ "url": "https://github.com/fukict/fukict/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/fukict/fukict.git",
18
+ "directory": "packages/vite-plugin"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Fukict Team",
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist",
35
+ "README.md"
36
+ ],
37
+ "dependencies": {
38
+ "@babel/core": "^7.26.0",
39
+ "@fukict/babel-preset": "0.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.6.3"
43
+ },
44
+ "peerDependencies": {
45
+ "vite": "^6.3.6"
46
+ },
47
+ "engines": {
48
+ "node": ">=16.0.0"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc",
52
+ "dev": "tsc --watch",
53
+ "lint": "tsc --noEmit",
54
+ "typecheck": "tsc --noEmit"
55
+ }
56
+ }