Installation
Prerequisites
Before installing Flexium, ensure you have the following:
- Node.js: Version 18.0 or higher (20.x LTS recommended)
- Package Manager: npm (bundled with Node.js), yarn, pnpm, or bun
- Operating System: Windows, macOS, or Linux
- Browser: Modern browser with ES2020+ support for development
To verify your Node.js installation:
node --version # Should output v18.0.0 or higherCreate a New Project
The fastest way to get started with Flexium is using the official scaffolding tool:
Using npm
npm create flexium@latest my-app
cd my-app
npm install
npm run devUsing Yarn
yarn create flexium my-app
cd my-app
yarn install
yarn devUsing pnpm
pnpm create flexium my-app
cd my-app
pnpm install
pnpm devUsing Bun
bun create flexium my-app
cd my-app
bun install
bun devThe scaffolding tool will prompt you to select:
- Project template (basic, router, full-featured)
- TypeScript support
- ESLint configuration
- Prettier setup
Install in Existing Project
You can add Flexium to an existing project using your preferred package manager:
Using npm
npm install flexiumFor development dependencies:
npm install -D vite-plugin-flexium @types/nodeUsing Yarn
yarn add flexiumFor development dependencies:
yarn add -D vite-plugin-flexium @types/nodeUsing pnpm
pnpm add flexiumFor development dependencies:
pnpm add -D vite-plugin-flexium @types/nodeUsing Bun
bun add flexiumFor development dependencies:
bun add -D vite-plugin-flexium @types/nodeVite Configuration
Flexium is designed to work seamlessly with Vite. We recommend using the official Vite plugin for automatic configuration.
Recommended: Using vite-plugin-flexium
Install the official Vite plugin:
npm install vite-plugin-flexium -DThen configure it in your Vite config:
// vite.config.ts
import { defineConfig } from 'vite'
import flexium from 'vite-plugin-flexium'
export default defineConfig({
plugins: [flexium()]
})The plugin automatically configures JSX, enables Hot Module Replacement (HMR), and integrates DevTools. See the Vite Plugin Guide for more details.
Advanced Vite Configuration
For more control over your build process, you can customize the Vite configuration:
// vite.config.ts
import { defineConfig } from 'vite'
import flexium from 'vite-plugin-flexium'
import path from 'path'
export default defineConfig({
plugins: [
flexium({
// Plugin options
hmr: true,
devtools: true,
jsx: 'automatic'
})
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
'@utils': path.resolve(__dirname, './src/utils'),
'@stores': path.resolve(__dirname, './src/stores')
}
},
server: {
port: 3000,
open: true,
cors: true
},
build: {
target: 'es2020',
outDir: 'dist',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
vendor: ['flexium']
}
}
}
},
optimizeDeps: {
include: ['flexium']
}
})Manual Configuration
If you prefer not to use the plugin, you can configure Vite manually:
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
esbuild: {
jsxImportSource: 'flexium',
jsxFactory: 'jsx',
jsxFragment: 'Fragment'
}
})Note: Manual configuration does not include HMR or DevTools integration.
TypeScript Setup and Configuration
Flexium has excellent TypeScript support out of the box. Here's how to configure it properly:
TypeScript Configuration
Create or update your tsconfig.json:
{
"compilerOptions": {
// JSX Configuration
"jsx": "react-jsx",
"jsxImportSource": "flexium",
// Module Configuration
"target": "ES2020",
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"moduleResolution": "bundler",
// Type Checking
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
// Path Aliases
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"],
"@utils/*": ["./src/utils/*"],
"@stores/*": ["./src/stores/*"]
},
// Build Options
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
// Output
"outDir": "./dist",
"removeComments": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
}TypeScript Types
Install necessary type definitions:
npm install -D @types/nodeType-Safe Components
Example of a fully typed Flexium component:
import { component, state } from 'flexium'
interface CounterProps {
initialCount?: number
step?: number
onCountChange?: (count: number) => void
}
export const Counter = component<CounterProps>(({ initialCount = 0, step = 1, onCountChange }) => {
const [count, setCount] = state(initialCount)
const increment = () => {
setCount(c => c + step)
onCountChange?.(count())
}
return () => (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
)
})IDE Setup
VS Code
Recommended extensions for the best development experience:
- ESLint (
dbaeumer.vscode-eslint) - JavaScript/TypeScript linting - Prettier (
esbenp.prettier-vscode) - Code formatting - TypeScript Vue Plugin (Volar) (
Vue.volar) - Enhanced TypeScript support - Path Intellisense (
christian-kohler.path-intellisense) - Path autocompletion - Error Lens (
usernamehw.errorlens) - Inline error highlighting
VS Code Settings
Create or update .vscode/settings.json:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"files.associations": {
"*.css": "css"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}VS Code Extensions Configuration
Create .vscode/extensions.json:
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"Vue.volar",
"christian-kohler.path-intellisense",
"usernamehw.errorlens"
]
}WebStorm / IntelliJ IDEA
WebStorm provides excellent support for Flexium out of the box:
- Enable TypeScript support in Settings > Languages & Frameworks > TypeScript
- Set Node interpreter to your local Node.js installation
- Enable Prettier in Settings > Languages & Frameworks > JavaScript > Prettier
- Enable ESLint in Settings > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint
WebStorm Settings
- Automatic formatting: Preferences > Tools > Actions on Save > Enable "Reformat code" and "Run eslint --fix"
- JSX support: WebStorm automatically recognizes JSX in
.tsxfiles - Path mapping: Automatically resolved from
tsconfig.jsonpaths
ESLint and Prettier Configuration
ESLint Setup
Install ESLint and necessary plugins:
npm install -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-importCreate .eslintrc.json:
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint", "import"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript"
],
"rules": {
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"import/order": ["error", {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
"newlines-between": "always",
"alphabetize": { "order": "asc" }
}]
},
"env": {
"browser": true,
"es2020": true,
"node": true
}
}Create .eslintignore:
node_modules
dist
build
coverage
*.config.js
*.config.tsPrettier Setup
Install Prettier:
npm install -D prettier eslint-config-prettierCreate .prettierrc:
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 100,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "lf"
}Create .prettierignore:
node_modules
dist
build
coverage
pnpm-lock.yaml
package-lock.json
yarn.lockUpdate .eslintrc.json to include Prettier:
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"prettier"
]
}Package Scripts
Add these scripts to your package.json:
{
"scripts": {
"lint": "eslint . --ext .ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"format": "prettier --write \"src/**/*.{ts,tsx,css,md}\"",
"format:check": "prettier --check \"src/**/*.{ts,tsx,css,md}\""
}
}Project Structure Recommendations
Here's a recommended project structure for Flexium applications:
my-flexium-app/
├── public/
│ ├── favicon.ico
│ └── assets/
├── src/
│ ├── components/
│ │ ├── common/
│ │ │ ├── Button.tsx
│ │ │ ├── Input.tsx
│ │ │ └── Modal.tsx
│ │ ├── layout/
│ │ │ ├── Header.tsx
│ │ │ ├── Footer.tsx
│ │ │ └── Sidebar.tsx
│ │ └── features/
│ │ ├── TodoList.tsx
│ │ └── UserProfile.tsx
│ ├── stores/
│ │ ├── userStore.ts
│ │ ├── todoStore.ts
│ │ └── index.ts
│ ├── utils/
│ │ ├── api.ts
│ │ ├── helpers.ts
│ │ └── constants.ts
│ ├── types/
│ │ ├── index.ts
│ │ └── api.ts
│ ├── styles/
│ │ ├── global.css
│ │ └── variables.css
│ ├── App.tsx
│ ├── main.tsx
│ └── vite-env.d.ts
├── .eslintrc.json
├── .prettierrc
├── .gitignore
├── tsconfig.json
├── vite.config.ts
├── package.json
└── README.mdDirectory Structure Guidelines
- components/: Reusable UI components
common/: Generic reusable componentslayout/: Layout-specific componentsfeatures/: Feature-specific components
- stores/: State management stores
- utils/: Utility functions and helpers
- types/: TypeScript type definitions
- styles/: Global styles and CSS variables
Development Workflow
Running the Development Server
Start the development server with hot module replacement:
npm run devThe server will typically run on http://localhost:5173 (or the next available port).
Building for Production
Create an optimized production build:
npm run buildThe built files will be output to the dist/ directory.
Previewing Production Build
Preview the production build locally:
npm run previewType Checking
Run TypeScript type checking:
npx tsc --noEmitAdd this to your package.json scripts:
{
"scripts": {
"type-check": "tsc --noEmit"
}
}Build Configuration
Production Optimization
Configure optimizations in vite.config.ts:
import { defineConfig } from 'vite'
import flexium from 'vite-plugin-flexium'
export default defineConfig({
plugins: [flexium()],
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
},
rollupOptions: {
output: {
manualChunks: {
vendor: ['flexium'],
utils: ['./src/utils/helpers']
}
}
},
chunkSizeWarningLimit: 1000
}
})Asset Handling
Configure how Vite handles static assets:
export default defineConfig({
build: {
assetsInlineLimit: 4096, // 4kb
assetsDir: 'assets'
}
})Environment Variables Setup
Creating Environment Files
Create environment files for different stages:
.env (default):
VITE_APP_TITLE=Flexium App
VITE_API_URL=http://localhost:3000.env.development:
VITE_APP_TITLE=Flexium App (Dev)
VITE_API_URL=http://localhost:3000
VITE_DEBUG=true.env.production:
VITE_APP_TITLE=Flexium App
VITE_API_URL=https://api.example.com
VITE_DEBUG=falseUsing Environment Variables
Access environment variables in your code:
const apiUrl = import.meta.env.VITE_API_URL
const isDebug = import.meta.env.VITE_DEBUG === 'true'
const isDev = import.meta.env.DEV
const isProd = import.meta.env.PRODType-Safe Environment Variables
Create src/vite-env.d.ts:
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_APP_TITLE: string
readonly VITE_API_URL: string
readonly VITE_DEBUG: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}Security Note
Never commit .env.local or .env.*.local files. Add them to .gitignore:
# Environment files
.env.local
.env.*.localTroubleshooting Common Issues
Issue: JSX is not recognized
Symptom: Error "React is not defined" or JSX syntax not recognized.
Solution: Ensure jsxImportSource is set in both tsconfig.json and vite.config.ts:
// tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "flexium"
}
}Issue: Module not found errors with path aliases
Symptom: TypeScript can't resolve path aliases like @/components.
Solution: Ensure path aliases are configured in both tsconfig.json and vite.config.ts:
// vite.config.ts
import path from 'path'
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
}
})Issue: Hot Module Replacement not working
Symptom: Changes don't reflect without manual refresh.
Solution:
- Ensure
vite-plugin-flexiumis installed and configured - Check that HMR is enabled in the plugin options
- Verify your component exports are named exports
Issue: Build fails with TypeScript errors
Symptom: Production build fails but development works.
Solution:
- Run
npm run type-checkto identify type errors - Enable
skipLibCheck: trueintsconfig.jsonas a temporary workaround - Fix type errors in your code
Issue: Large bundle size
Symptom: Production bundle is larger than expected.
Solution:
- Use dynamic imports for code splitting:
const HeavyComponent = lazy(() => import('./HeavyComponent'))- Configure manual chunks in
vite.config.ts - Run
npm run build -- --mode analyzeto visualize bundle
Issue: Port already in use
Symptom: Development server fails to start.
Solution: Change the port in vite.config.ts:
export default defineConfig({
server: {
port: 3001
}
})Issue: CORS errors in development
Symptom: API requests fail with CORS errors.
Solution: Configure proxy in vite.config.ts:
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})Getting Help
If you encounter issues not covered here:
- Check the GitHub Issues
- Join the Discord Community
- Read the FAQ
Next Steps
Now that you have Flexium installed and configured, you're ready to start building:
- Learn the Core Concepts
- Build your first Component
- Explore State Management
- Check out Examples