@biggora/claude-plugins 1.1.1 → 1.2.2
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/.claude/settings.local.json +3 -1
- package/README.md +24 -17
- package/package.json +1 -1
- package/registry/registry.json +319 -244
- package/specs/coding.md +24 -0
- package/specs/pod.md +2 -0
- package/src/skills/captcha/README.md +221 -0
- package/src/skills/captcha/SKILL.md +355 -0
- package/src/skills/captcha/references/captcha-types.md +254 -0
- package/src/skills/captcha/references/services.md +172 -0
- package/src/skills/captcha/references/stealth.md +238 -0
- package/src/skills/captcha/scripts/solve_captcha.py +323 -0
- package/src/skills/captcha/scripts/solve_image_grid.py +350 -0
- package/src/skills/codex-cli/SKILL.md +21 -11
- package/src/skills/gemini-cli/SKILL.md +27 -13
- package/src/skills/gemini-cli/references/commands.md +21 -14
- package/src/skills/gemini-cli/references/configuration.md +23 -18
- package/src/skills/gemini-cli/references/headless-and-scripting.md +7 -17
- package/src/skills/gemini-cli/references/mcp-and-extensions.md +12 -6
- package/src/skills/google-merchant-api/SKILL.md +581 -0
- package/src/skills/google-merchant-api/references/accounts.md +247 -0
- package/src/skills/google-merchant-api/references/content-api-legacy.md +216 -0
- package/src/skills/google-merchant-api/references/datasources.md +233 -0
- package/src/skills/google-merchant-api/references/inventories.md +201 -0
- package/src/skills/google-merchant-api/references/migration.md +267 -0
- package/src/skills/google-merchant-api/references/products.md +316 -0
- package/src/skills/google-merchant-api/references/promotions.md +201 -0
- package/src/skills/google-merchant-api/references/reports.md +240 -0
- package/src/skills/lv-aggregators-api/SKILL.md +113 -0
- package/src/skills/lv-aggregators-api/references/integration-guide.md +368 -0
- package/src/skills/lv-aggregators-api/references/kurpirkt.md +103 -0
- package/src/skills/lv-aggregators-api/references/salidzini.md +122 -0
- package/src/skills/notebook-lm/SKILL.md +1 -1
- package/src/skills/screen-recording/SKILL.md +243 -213
- package/src/skills/screen-recording/references/design-patterns.md +4 -2
- package/src/skills/screen-recording/references/ffmpeg-recording.md +473 -0
- package/src/skills/screen-recording/references/{approach1-programmatic.md → programmatic-generation.md} +45 -22
- package/src/skills/screen-recording/references/python-fallback.md +222 -0
- package/src/skills/tailwindcss-best-practices/SKILL.md +180 -0
- package/src/skills/tailwindcss-best-practices/references/best-practices-utility-patterns.md +87 -0
- package/src/skills/tailwindcss-best-practices/references/core-installation.md +109 -0
- package/src/skills/tailwindcss-best-practices/references/core-preflight.md +200 -0
- package/src/skills/tailwindcss-best-practices/references/core-responsive.md +163 -0
- package/src/skills/tailwindcss-best-practices/references/core-source-detection.md +114 -0
- package/src/skills/tailwindcss-best-practices/references/core-theme.md +108 -0
- package/src/skills/tailwindcss-best-practices/references/core-utility-classes.md +59 -0
- package/src/skills/tailwindcss-best-practices/references/core-variants.md +204 -0
- package/src/skills/tailwindcss-best-practices/references/effects-form-controls.md +76 -0
- package/src/skills/tailwindcss-best-practices/references/effects-mask.md +91 -0
- package/src/skills/tailwindcss-best-practices/references/effects-scroll-snap.md +59 -0
- package/src/skills/tailwindcss-best-practices/references/effects-text-shadow.md +78 -0
- package/src/skills/tailwindcss-best-practices/references/effects-transition-animation.md +80 -0
- package/src/skills/tailwindcss-best-practices/references/effects-visibility-interactivity.md +82 -0
- package/src/skills/tailwindcss-best-practices/references/features-content-detection.md +175 -0
- package/src/skills/tailwindcss-best-practices/references/features-custom-styles.md +203 -0
- package/src/skills/tailwindcss-best-practices/references/features-dark-mode.md +137 -0
- package/src/skills/tailwindcss-best-practices/references/features-functions-directives.md +241 -0
- package/src/skills/tailwindcss-best-practices/references/features-upgrade.md +160 -0
- package/src/skills/tailwindcss-best-practices/references/layout-aspect-ratio.md +39 -0
- package/src/skills/tailwindcss-best-practices/references/layout-columns.md +80 -0
- package/src/skills/tailwindcss-best-practices/references/layout-display.md +110 -0
- package/src/skills/tailwindcss-best-practices/references/layout-flexbox.md +112 -0
- package/src/skills/tailwindcss-best-practices/references/layout-grid.md +87 -0
- package/src/skills/tailwindcss-best-practices/references/layout-height.md +97 -0
- package/src/skills/tailwindcss-best-practices/references/layout-inset.md +103 -0
- package/src/skills/tailwindcss-best-practices/references/layout-logical-properties.md +92 -0
- package/src/skills/tailwindcss-best-practices/references/layout-margin.md +126 -0
- package/src/skills/tailwindcss-best-practices/references/layout-min-max-sizing.md +63 -0
- package/src/skills/tailwindcss-best-practices/references/layout-object-fit-position.md +64 -0
- package/src/skills/tailwindcss-best-practices/references/layout-overflow.md +57 -0
- package/src/skills/tailwindcss-best-practices/references/layout-padding.md +77 -0
- package/src/skills/tailwindcss-best-practices/references/layout-position.md +85 -0
- package/src/skills/tailwindcss-best-practices/references/layout-tables.md +67 -0
- package/src/skills/tailwindcss-best-practices/references/layout-width.md +102 -0
- package/src/skills/tailwindcss-best-practices/references/transform-base.md +68 -0
- package/src/skills/tailwindcss-best-practices/references/transform-rotate.md +70 -0
- package/src/skills/tailwindcss-best-practices/references/transform-scale.md +83 -0
- package/src/skills/tailwindcss-best-practices/references/transform-skew.md +62 -0
- package/src/skills/tailwindcss-best-practices/references/transform-translate.md +77 -0
- package/src/skills/tailwindcss-best-practices/references/typography-font-text.md +142 -0
- package/src/skills/tailwindcss-best-practices/references/typography-list-style.md +65 -0
- package/src/skills/tailwindcss-best-practices/references/typography-text-align.md +60 -0
- package/src/skills/tailwindcss-best-practices/references/visual-background.md +76 -0
- package/src/skills/tailwindcss-best-practices/references/visual-border.md +108 -0
- package/src/skills/tailwindcss-best-practices/references/visual-effects.md +111 -0
- package/src/skills/tailwindcss-best-practices/references/visual-svg.md +82 -0
- package/src/skills/test-mobile-app/SKILL.md +11 -6
- package/src/skills/test-mobile-app/scripts/analyze_apk.py +15 -4
- package/src/skills/test-mobile-app/scripts/check_environment.py +5 -5
- package/src/skills/test-mobile-app/scripts/run_tests.py +1 -1
- package/src/skills/test-web-ui/SKILL.md +264 -84
- package/src/skills/test-web-ui/scripts/discover.py +25 -12
- package/src/skills/test-web-ui/scripts/run_tests.py +3 -2
- package/src/skills/tm-search/SKILL.md +242 -106
- package/src/skills/tm-search/references/scraping-fallback.md +60 -95
- package/src/skills/tm-search/scripts/tm_search.py +453 -375
- package/src/skills/vite-best-practices/SKILL.md +115 -0
- package/src/skills/vite-best-practices/references/build-and-ssr.md +255 -0
- package/src/skills/vite-best-practices/references/core-config.md +231 -0
- package/src/skills/vite-best-practices/references/core-features.md +222 -0
- package/src/skills/vite-best-practices/references/core-plugin-api.md +294 -0
- package/src/skills/vite-best-practices/references/environment-api.md +108 -0
- package/src/skills/vite-best-practices/references/rolldown-migration.md +242 -0
- package/src/skills/screen-recording/references/approach2-xvfb.md +0 -232
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vite-best-practices
|
|
3
|
+
description: Vite build tool configuration, plugin API, SSR, library mode, and Vite 8 Rolldown/Oxc migration. Use when working with Vite projects, vite.config.ts, Vite plugins, building libraries or SSR apps with Vite, migrating from older Vite versions, or configuring Rolldown/Oxc options. Also use when the user mentions HMR, import.meta.glob, virtual modules, or Vite environment variables.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Vite
|
|
7
|
+
|
|
8
|
+
> Based on Vite 8.0 stable (March 2026). Vite 8 uses Rolldown bundler and Oxc transformer, replacing esbuild + Rollup.
|
|
9
|
+
|
|
10
|
+
Vite is a next-generation frontend build tool with fast dev server (native ESM + HMR) and optimized production builds powered by Rolldown.
|
|
11
|
+
|
|
12
|
+
## Key Vite 8 Changes
|
|
13
|
+
|
|
14
|
+
Vite 8 replaces the dual esbuild+Rollup architecture with Rolldown (unified Rust-based bundler) and Oxc (transformer/minifier). A **compatibility layer** auto-converts old `esbuild` and `rollupOptions` configs, but both are deprecated — always use the new names in new code:
|
|
15
|
+
|
|
16
|
+
| Deprecated (still works) | Replacement |
|
|
17
|
+
|--------------------------|-------------|
|
|
18
|
+
| `build.rollupOptions` | `build.rolldownOptions` |
|
|
19
|
+
| `esbuild` | `oxc` |
|
|
20
|
+
| `optimizeDeps.esbuildOptions` | `optimizeDeps.rolldownOptions` |
|
|
21
|
+
| `build.minify: 'esbuild'` | `build.minify: 'oxc'` (default) |
|
|
22
|
+
|
|
23
|
+
## Preferences
|
|
24
|
+
|
|
25
|
+
- Use TypeScript: prefer `vite.config.ts`
|
|
26
|
+
- Always use ESM — avoid CommonJS
|
|
27
|
+
- Use `import.meta.dirname` (ESM) not `__dirname` (CJS) in config files
|
|
28
|
+
- Use `rolldownOptions` not `rollupOptions` in new code
|
|
29
|
+
- Use `oxc` not `esbuild` in new code
|
|
30
|
+
|
|
31
|
+
## Core
|
|
32
|
+
|
|
33
|
+
| Topic | Description | Reference |
|
|
34
|
+
|-------|-------------|-----------|
|
|
35
|
+
| Configuration | `vite.config.ts`, `defineConfig`, conditional configs, `loadEnv`, new v8 options | [core-config](references/core-config.md) |
|
|
36
|
+
| Features | `import.meta.glob`, asset queries, `import.meta.env`, HMR API, CSS modules | [core-features](references/core-features.md) |
|
|
37
|
+
| Plugin API | Vite/Rolldown hooks, virtual modules, hook filters, plugin ordering | [core-plugin-api](references/core-plugin-api.md) |
|
|
38
|
+
|
|
39
|
+
## Build & SSR
|
|
40
|
+
|
|
41
|
+
| Topic | Description | Reference |
|
|
42
|
+
|-------|-------------|-----------|
|
|
43
|
+
| Build & SSR | Library mode, SSR middleware, `ssrLoadModule`, multi-page apps, JavaScript API | [build-and-ssr](references/build-and-ssr.md) |
|
|
44
|
+
|
|
45
|
+
## Advanced
|
|
46
|
+
|
|
47
|
+
| Topic | Description | Reference |
|
|
48
|
+
|-------|-------------|-----------|
|
|
49
|
+
| Environment API | Vite 6+ multi-environment support, custom runtimes | [environment-api](references/environment-api.md) |
|
|
50
|
+
| Rolldown Migration | Vite 8 migration: complete esbuild→oxc and rollupOptions→rolldownOptions mapping, breaking changes | [rolldown-migration](references/rolldown-migration.md) |
|
|
51
|
+
|
|
52
|
+
## Quick Reference
|
|
53
|
+
|
|
54
|
+
### CLI Commands
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
vite # Start dev server
|
|
58
|
+
vite build # Production build
|
|
59
|
+
vite preview # Preview production build
|
|
60
|
+
vite build --ssr # SSR build
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Common Config (Vite 8)
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { defineConfig } from 'vite'
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
plugins: [],
|
|
70
|
+
resolve: {
|
|
71
|
+
alias: { '@': '/src' },
|
|
72
|
+
tsconfigPaths: true, // New in v8: auto-resolve TS path aliases
|
|
73
|
+
},
|
|
74
|
+
server: {
|
|
75
|
+
port: 3000,
|
|
76
|
+
proxy: { '/api': 'http://localhost:8080' },
|
|
77
|
+
forwardConsole: true, // New in v8: browser logs → terminal
|
|
78
|
+
},
|
|
79
|
+
build: {
|
|
80
|
+
target: 'esnext',
|
|
81
|
+
outDir: 'dist',
|
|
82
|
+
rolldownOptions: {}, // NOT rollupOptions
|
|
83
|
+
},
|
|
84
|
+
oxc: { // NOT esbuild
|
|
85
|
+
jsx: {
|
|
86
|
+
runtime: 'automatic',
|
|
87
|
+
importSource: 'react',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Official Plugins
|
|
94
|
+
|
|
95
|
+
- `@vitejs/plugin-react` v6 — React with Oxc transforms (Babel removed)
|
|
96
|
+
- `@vitejs/plugin-react-swc` — React with SWC
|
|
97
|
+
- `@vitejs/plugin-vue` — Vue 3 SFC support
|
|
98
|
+
- `@vitejs/plugin-vue-jsx` — Vue 3 JSX
|
|
99
|
+
- `@vitejs/plugin-legacy` — Legacy browser support
|
|
100
|
+
|
|
101
|
+
### Oxc JSX Quick Reference
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// React (automatic runtime — default)
|
|
105
|
+
oxc: { jsx: { runtime: 'automatic', importSource: 'react' } }
|
|
106
|
+
|
|
107
|
+
// Preact (automatic)
|
|
108
|
+
oxc: { jsx: { runtime: 'automatic', importSource: 'preact' } }
|
|
109
|
+
|
|
110
|
+
// Preact (classic with h/Fragment)
|
|
111
|
+
oxc: { jsx: { runtime: 'classic', pragma: 'h', pragmaFrag: 'Fragment' } }
|
|
112
|
+
|
|
113
|
+
// Auto-inject React import (legacy patterns)
|
|
114
|
+
oxc: { jsxInject: `import React from 'react'` }
|
|
115
|
+
```
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vite-build-ssr
|
|
3
|
+
description: Vite 8 library mode and SSR configuration
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Build and SSR
|
|
7
|
+
|
|
8
|
+
## Library Mode
|
|
9
|
+
|
|
10
|
+
Build a library for distribution:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
// vite.config.ts
|
|
14
|
+
import { resolve } from 'node:path'
|
|
15
|
+
import { defineConfig } from 'vite'
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
build: {
|
|
19
|
+
lib: {
|
|
20
|
+
entry: resolve(import.meta.dirname, 'lib/main.ts'),
|
|
21
|
+
name: 'MyLib',
|
|
22
|
+
fileName: 'my-lib',
|
|
23
|
+
},
|
|
24
|
+
rolldownOptions: {
|
|
25
|
+
external: ['vue', 'react'],
|
|
26
|
+
output: {
|
|
27
|
+
globals: {
|
|
28
|
+
vue: 'Vue',
|
|
29
|
+
react: 'React',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Note:** Use `import.meta.dirname` (ESM) not `__dirname` (CJS).
|
|
38
|
+
|
|
39
|
+
### Multiple Entries
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
build: {
|
|
43
|
+
lib: {
|
|
44
|
+
entry: {
|
|
45
|
+
'my-lib': resolve(import.meta.dirname, 'lib/main.ts'),
|
|
46
|
+
secondary: resolve(import.meta.dirname, 'lib/secondary.ts'),
|
|
47
|
+
},
|
|
48
|
+
name: 'MyLib',
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Output Formats
|
|
54
|
+
|
|
55
|
+
- Single entry: `es` and `umd`
|
|
56
|
+
- Multiple entries: `es` and `cjs`
|
|
57
|
+
|
|
58
|
+
### Package.json Setup
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"name": "my-lib",
|
|
63
|
+
"type": "module",
|
|
64
|
+
"files": ["dist"],
|
|
65
|
+
"main": "./dist/my-lib.umd.cjs",
|
|
66
|
+
"module": "./dist/my-lib.js",
|
|
67
|
+
"exports": {
|
|
68
|
+
".": {
|
|
69
|
+
"import": {
|
|
70
|
+
"types": "./dist/types/index.d.ts",
|
|
71
|
+
"default": "./dist/my-lib.js"
|
|
72
|
+
},
|
|
73
|
+
"require": {
|
|
74
|
+
"types": "./dist/types/index.d.ts",
|
|
75
|
+
"default": "./dist/my-lib.umd.cjs"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"./style.css": "./dist/my-lib.css"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Tip:** List `types` first in each export condition — Node.js resolves conditions top-to-bottom.
|
|
84
|
+
|
|
85
|
+
## Multi-Page App
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
export default defineConfig({
|
|
89
|
+
build: {
|
|
90
|
+
rolldownOptions: {
|
|
91
|
+
input: {
|
|
92
|
+
main: resolve(import.meta.dirname, 'index.html'),
|
|
93
|
+
nested: resolve(import.meta.dirname, 'nested/index.html'),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Chunk Splitting (Vite 8)
|
|
101
|
+
|
|
102
|
+
The `manualChunks` object form is removed in Vite 8. The function form is deprecated — use `codeSplitting` instead for advanced chunk control.
|
|
103
|
+
|
|
104
|
+
## SSR Development
|
|
105
|
+
|
|
106
|
+
### Middleware Mode
|
|
107
|
+
|
|
108
|
+
Use Vite as middleware in a custom server:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import express from 'express'
|
|
112
|
+
import { createServer as createViteServer } from 'vite'
|
|
113
|
+
|
|
114
|
+
const app = express()
|
|
115
|
+
|
|
116
|
+
const vite = await createViteServer({
|
|
117
|
+
server: { middlewareMode: true },
|
|
118
|
+
appType: 'custom',
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
app.use(vite.middlewares)
|
|
122
|
+
|
|
123
|
+
app.use('*all', async (req, res, next) => {
|
|
124
|
+
const url = req.originalUrl
|
|
125
|
+
|
|
126
|
+
// 1. Read and transform index.html
|
|
127
|
+
let template = await fs.readFile('index.html', 'utf-8')
|
|
128
|
+
template = await vite.transformIndexHtml(url, template)
|
|
129
|
+
|
|
130
|
+
// 2. Load server entry
|
|
131
|
+
const { render } = await vite.ssrLoadModule('/src/entry-server.ts')
|
|
132
|
+
|
|
133
|
+
// 3. Render app
|
|
134
|
+
const appHtml = await render(url)
|
|
135
|
+
|
|
136
|
+
// 4. Inject into template
|
|
137
|
+
const html = template.replace('<!--ssr-outlet-->', appHtml)
|
|
138
|
+
|
|
139
|
+
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
app.listen(5173)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### SSR Build
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"scripts": {
|
|
150
|
+
"build:client": "vite build --outDir dist/client",
|
|
151
|
+
"build:server": "vite build --outDir dist/server --ssr src/entry-server.ts"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The `--ssr` flag:
|
|
157
|
+
- Externalizes dependencies by default
|
|
158
|
+
- Outputs for Node.js consumption
|
|
159
|
+
|
|
160
|
+
### SSR Manifest
|
|
161
|
+
|
|
162
|
+
Generate asset mapping for preload hints:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
vite build --outDir dist/client --ssrManifest
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Creates `dist/client/.vite/ssr-manifest.json` mapping module IDs to chunks.
|
|
169
|
+
|
|
170
|
+
### SSR Externals
|
|
171
|
+
|
|
172
|
+
Control which deps get bundled vs externalized:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
export default defineConfig({
|
|
176
|
+
ssr: {
|
|
177
|
+
noExternal: ['some-package'], // Bundle this dep
|
|
178
|
+
external: ['another-package'], // Externalize this dep
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Conditional Logic
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
if (import.meta.env.SSR) {
|
|
187
|
+
// Server-only code (tree-shaken from client)
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## JavaScript API
|
|
192
|
+
|
|
193
|
+
### createServer
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { createServer } from 'vite'
|
|
197
|
+
|
|
198
|
+
const server = await createServer({
|
|
199
|
+
configFile: false,
|
|
200
|
+
root: import.meta.dirname,
|
|
201
|
+
server: { port: 1337 },
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
await server.listen()
|
|
205
|
+
server.printUrls()
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### build
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { build } from 'vite'
|
|
212
|
+
|
|
213
|
+
await build({
|
|
214
|
+
root: './project',
|
|
215
|
+
build: { outDir: 'dist' },
|
|
216
|
+
})
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Vite 8:** `build()` throws `BundleError` (not raw error) with `.errors?: RolldownError[]` array.
|
|
220
|
+
|
|
221
|
+
### preview
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import { preview } from 'vite'
|
|
225
|
+
|
|
226
|
+
const previewServer = await preview({
|
|
227
|
+
preview: { port: 8080, open: true },
|
|
228
|
+
})
|
|
229
|
+
previewServer.printUrls()
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### resolveConfig
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { resolveConfig } from 'vite'
|
|
236
|
+
|
|
237
|
+
const config = await resolveConfig({}, 'build')
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### loadEnv
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
import { loadEnv } from 'vite'
|
|
244
|
+
|
|
245
|
+
const env = loadEnv('development', process.cwd(), '')
|
|
246
|
+
// Loads all env vars (empty prefix = no filtering)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
<!--
|
|
250
|
+
Source references:
|
|
251
|
+
- https://vite.dev/guide/build
|
|
252
|
+
- https://vite.dev/guide/ssr
|
|
253
|
+
- https://vite.dev/guide/api-javascript
|
|
254
|
+
- https://vite.dev/guide/migration
|
|
255
|
+
-->
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vite-config
|
|
3
|
+
description: Vite 8 configuration patterns using vite.config.ts
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Vite Configuration
|
|
7
|
+
|
|
8
|
+
## Basic Setup
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// vite.config.ts
|
|
12
|
+
import { defineConfig } from 'vite'
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
// config options
|
|
16
|
+
})
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Vite auto-resolves `vite.config.ts` from project root. Supports ES modules syntax regardless of `package.json` type.
|
|
20
|
+
|
|
21
|
+
## Conditional Config
|
|
22
|
+
|
|
23
|
+
Export a function to access command and mode:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
|
27
|
+
if (command === 'serve') {
|
|
28
|
+
return { /* dev config */ }
|
|
29
|
+
} else {
|
|
30
|
+
return { /* build config */ }
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- `command`: `'serve'` during dev, `'build'` for production
|
|
36
|
+
- `mode`: `'development'` or `'production'` (or custom via `--mode`)
|
|
37
|
+
|
|
38
|
+
## Async Config
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
export default defineConfig(async ({ command, mode }) => {
|
|
42
|
+
const data = await fetchSomething()
|
|
43
|
+
return { /* config */ }
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Using Environment Variables in Config
|
|
48
|
+
|
|
49
|
+
`.env` files are loaded **after** config resolution. Use `loadEnv` to access them in config:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { defineConfig, loadEnv } from 'vite'
|
|
53
|
+
|
|
54
|
+
export default defineConfig(({ mode }) => {
|
|
55
|
+
const env = loadEnv(mode, process.cwd(), '')
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
define: {
|
|
59
|
+
__APP_ENV__: JSON.stringify(env.APP_ENV),
|
|
60
|
+
},
|
|
61
|
+
server: {
|
|
62
|
+
port: env.APP_PORT ? Number(env.APP_PORT) : 5173,
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Key Config Options
|
|
69
|
+
|
|
70
|
+
### resolve.alias
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
resolve: {
|
|
75
|
+
alias: {
|
|
76
|
+
'@': '/src',
|
|
77
|
+
'~': '/src',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### resolve.tsconfigPaths (Vite 8)
|
|
84
|
+
|
|
85
|
+
Auto-resolve TypeScript path aliases from `tsconfig.json`:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
export default defineConfig({
|
|
89
|
+
resolve: {
|
|
90
|
+
tsconfigPaths: true, // default: false (small perf cost)
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### define (Global Constants)
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
export default defineConfig({
|
|
99
|
+
define: {
|
|
100
|
+
__APP_VERSION__: JSON.stringify('1.0.0'),
|
|
101
|
+
__API_URL__: 'window.__backend_api_url',
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Values must be JSON-serializable or single identifiers. Non-strings auto-wrapped with `JSON.stringify`.
|
|
107
|
+
|
|
108
|
+
### plugins
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import vue from '@vitejs/plugin-vue'
|
|
112
|
+
|
|
113
|
+
export default defineConfig({
|
|
114
|
+
plugins: [vue()],
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Plugins array is flattened; falsy values ignored.
|
|
119
|
+
|
|
120
|
+
### oxc (Vite 8 — replaces esbuild)
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
export default defineConfig({
|
|
124
|
+
oxc: {
|
|
125
|
+
jsx: {
|
|
126
|
+
runtime: 'automatic', // or 'classic'
|
|
127
|
+
importSource: 'react',
|
|
128
|
+
},
|
|
129
|
+
jsxInject: `import React from 'react'`, // auto-inject
|
|
130
|
+
include: ['**/*.ts', '**/*.tsx'], // default: ts, jsx, tsx
|
|
131
|
+
exclude: ['node_modules/**'],
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Set `oxc: false` to disable Oxc transformation entirely.
|
|
137
|
+
|
|
138
|
+
**Note:** The old `esbuild` option still works via compatibility layer but is deprecated. Always use `oxc` in new code.
|
|
139
|
+
|
|
140
|
+
### server.proxy
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
export default defineConfig({
|
|
144
|
+
server: {
|
|
145
|
+
proxy: {
|
|
146
|
+
'/api': {
|
|
147
|
+
target: 'http://localhost:3000',
|
|
148
|
+
changeOrigin: true,
|
|
149
|
+
rewrite: (path) => path.replace(/^\/api/, ''),
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### server.forwardConsole (Vite 8)
|
|
157
|
+
|
|
158
|
+
Route browser console logs to the dev server terminal:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
export default defineConfig({
|
|
162
|
+
server: {
|
|
163
|
+
forwardConsole: true, // useful for AI coding agents detecting runtime errors
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### devtools (Vite 8 — Experimental)
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
export default defineConfig({
|
|
172
|
+
devtools: true, // requires @vitejs/devtools installed; build mode only
|
|
173
|
+
})
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### build.target
|
|
177
|
+
|
|
178
|
+
Default: Baseline Widely Available browsers (Chrome 111+, Firefox 114+, Safari 16.4+).
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
export default defineConfig({
|
|
182
|
+
build: {
|
|
183
|
+
target: 'esnext', // or 'es2020', ['chrome90', 'firefox88']
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### build.rolldownOptions (Vite 8 — replaces rollupOptions)
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
export default defineConfig({
|
|
192
|
+
build: {
|
|
193
|
+
rolldownOptions: {
|
|
194
|
+
external: ['vue'],
|
|
195
|
+
output: {
|
|
196
|
+
globals: { vue: 'Vue' },
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Note:** `build.rollupOptions` still works via compat layer but is deprecated.
|
|
204
|
+
|
|
205
|
+
## TypeScript Intellisense
|
|
206
|
+
|
|
207
|
+
For plain JS config files:
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
/** @type {import('vite').UserConfig} */
|
|
211
|
+
export default {
|
|
212
|
+
// ...
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Or use `satisfies`:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import type { UserConfig } from 'vite'
|
|
220
|
+
|
|
221
|
+
export default {
|
|
222
|
+
// ...
|
|
223
|
+
} satisfies UserConfig
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
<!--
|
|
227
|
+
Source references:
|
|
228
|
+
- https://vite.dev/config/
|
|
229
|
+
- https://vite.dev/guide/
|
|
230
|
+
- https://vite.dev/guide/migration
|
|
231
|
+
-->
|