@fukict/vite-plugin
v0.1.8
Published
Vite plugin for Fukict framework
Maintainers
Readme
@fukict/vite-plugin
Official Vite plugin for Fukict framework.
Features
- ✅ Zero-config setup
- ✅ TypeScript support (built-in)
- ✅ Auto component wrapping with
defineFukict - ✅ JSX to hyperscript transformation
- ✅ Development mode enhancements
- ✅ Source map support
Installation
pnpm add -D @fukict/vite-plugin
pnpm add @fukict/basicUsage
Basic Setup
vite.config.ts:
import fukict from '@fukict/vite-plugin';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [fukict()],
});That's it! The plugin will automatically:
- Transform JSX to
hyperscript()calls - Auto-wrap components with
defineFukict() - Handle TypeScript syntax
- Inject
displayNamein development mode
With Options
import fukict from '@fukict/vite-plugin';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
fukict({
// Include patterns (default: /\.[jt]sx$/)
include: /\.[jt]sx$/,
// Exclude patterns (default: /node_modules/)
exclude: /node_modules/,
// Babel options
babel: {
// Development mode (default: NODE_ENV !== 'production')
development: true,
// TypeScript support (default: true)
typescript: true,
},
}),
],
});Options
include
Type: RegExp | RegExp[]
Default: /\.[jt]sx$/
Files to include for transformation.
Example:
fukict({
include: [/\.tsx$/, /\.jsx$/],
});exclude
Type: RegExp | RegExp[]
Default: /node_modules/
Files to exclude from transformation.
Example:
fukict({
exclude: [/node_modules/, /\.spec\.tsx$/],
});babel.development
Type: boolean
Default: process.env.NODE_ENV !== 'production'
Enable development mode features (like displayName injection).
babel.typescript
Type: boolean
Default: true
Enable TypeScript support.
How It Works
The plugin uses @fukict/babel-preset under the hood to transform your code:
// Input
const Greeting = ({ name }) => <div>Hello {name}</div>;
// Output
import { defineFukict, hyperscript } from '@fukict/basic';
const Greeting = defineFukict(({ name }) =>
hyperscript('div', null, ['Hello ', name])
);
Greeting.displayName = 'Greeting'; // in development modeTypeScript Configuration
tsconfig.json:
{
"compilerOptions": {
"jsx": "preserve",
"jsxImportSource": "@fukict/basic"
}
}Examples
Basic Counter
// src/Counter.tsx
export const Counter = () => {
let count = 0;
const increment = () => {
count++;
// Re-render logic here
};
return (
<div>
<p>Count: {count}</p>
<button on:click={increment}>+</button>
</div>
);
};With Class Component
import { Fukict } from '@fukict/basic';
export class Timer extends Fukict<{}> {
private count = 0;
private timer?: number;
mounted() {
this.timer = setInterval(() => {
this.count++;
this.update(this.props);
}, 1000);
}
beforeUnmount() {
clearInterval(this.timer);
}
render() {
return <div>Timer: {this.count}</div>;
}
}FAQ
Q: Do I need to manually configure Babel?
A: No! The plugin automatically configures everything for you.
Q: Can I use this with other Vite plugins?
A: Yes, just add it to the plugins array along with other plugins.
Q: Does it work with TypeScript?
A: Yes, TypeScript support is built-in and enabled by default.
Q: How do I disable auto component wrapping?
A: Use the @nofukict comment:
/** @nofukict */
const MyFunction = () => <div />;Troubleshooting
JSX not transforming
Check:
- File extension is
.jsxor.tsx tsconfig.jsonhas"jsx": "preserve"- Plugin is added to Vite config
TypeScript errors
Check:
@fukict/basicis installedjsxImportSourceis set to"@fukict/basic"- TypeScript version >= 5.0.0
Related Packages
- @fukict/basic - Fukict runtime (required)
- @fukict/babel-preset - Babel preset (used internally)
License
MIT
