@lark-apaas/fullstack-vite-preset
v1.0.20
Published
Vite preset for Fullstack applications, providing a complete replacement for `@lark-apaas/fullstack-rspack-preset`.
Readme
@lark-apaas/fullstack-vite-preset
Vite preset for Fullstack applications, providing a complete replacement for @lark-apaas/fullstack-rspack-preset.
Installation
npm install @lark-apaas/fullstack-vite-preset viteUsage
Basic Usage
Create a vite.config.ts file in your project root:
import path from 'path';
import { defineConfig } from '@lark-apaas/fullstack-vite-preset';
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'client/src'),
},
},
});Environment Variables
The preset automatically reads the following environment variables:
| Variable | Description | Default |
|----------|-------------|---------|
| NODE_ENV | development | production | development |
| NEED_ROUTES | Enable route parsing | true |
| CLIENT_BASE_PATH | Client base path | / |
| ASSETS_CDN_PATH | Production CDN path | / |
| SERVER_PORT | Backend server port | 3000 |
| CLIENT_DEV_PORT | Vite dev server port | 8080 |
| CLIENT_DEV_HOST | Vite dev server host | localhost |
| LOG_DIR | Log directory | ./logs |
Scripts
Update your package.json scripts:
{
"scripts": {
"dev:client": "vite --config vite.config.ts",
"build:client": "vite build --config vite.config.ts",
"preview:client": "vite preview --config vite.config.ts"
}
}Features
Included Plugins
- React Plugin: With automatic JSX runtime and styled-jsx support via Babel
- Route Parser Plugin: Automatically parses React Router routes from
app.tsx - Slardar Plugin: Injects performance monitoring SDK
- View Context Plugin: Injects server-side context variables
- OG Meta Plugin: Injects Open Graph meta tags
- Module Alias Plugin: Provides enhanced
clsx(with tailwind-merge) andecharts(with theme) - HMR Timing Plugin: Tracks and reports HMR compilation metrics
Module Aliases
The preset automatically replaces:
clsx- Enhanced withtailwind-mergefor automatic Tailwind class deduplicationecharts- Pre-configured with a shadcn-compatible theme (ud)
Dev Server Features
- Proxy configuration for
/apiand/__innerapi__routes - HTML requests proxied to backend server
- SnapDom proxy middleware for debugging
- Dev logs and OpenAPI middleware integration
Build Features
- Source maps in development
- Terser minification in production
- Code splitting enabled (Vite default)
- PostCSS with
postcss-importplugin
HTML Template
Ensure your client/index.html uses ES module scripts:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fullstack App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/client/src/index.tsx"></script>
</body>
</html>Migration from Rspack Preset
- Replace
@lark-apaas/fullstack-rspack-presetwith@lark-apaas/fullstack-vite-preset - Rename
rspack.config.jstovite.config.ts - Update the config to use the new
defineConfigfunction - Update
client/index.htmlto usetype="module"for scripts - Update package.json scripts to use
viteinstead ofrspack
License
MIT
