← 返回
未分类 中文

Vite Config Validator

Validate Vite configuration files (JSON-exported) for structural correctness, build settings, server security, resolve/CSS hygiene, plugin deprecations, and...
验证 Vite 配置文件(JSON 导出)的结构正确性、构建设置、服务器安全、resolve/CSS 规范以及插件废弃情况等。
charlie-morrison charlie-morrison 来源
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 377
下载
💾 1
安装
1
版本
#latest

概述

Vite Config Validator

Validate Vite configuration files exported as JSON for structural correctness, build settings, server configuration, resolve/CSS options, plugin hygiene, and best practices. Uses pure Python 3 stdlib (json, argparse, re, os, sys) -- no external dependencies.

Since Vite configs are JS/TS (vite.config.ts), the validator works with JSON-exported snapshots. Export your config first:

node -e "import('./vite.config.ts').then(m => console.log(JSON.stringify(m.default)))" > vite.config.json

Then validate the JSON output.

Commands

validate -- Full validation with all rules

python3 scripts/vite_config_validator.py validate vite.config.json
python3 scripts/vite_config_validator.py validate vite.config.json --strict
python3 scripts/vite_config_validator.py validate vite.config.json --format json

check -- Quick check (errors and warnings only)

python3 scripts/vite_config_validator.py check vite.config.json
python3 scripts/vite_config_validator.py check vite.config.json --format summary

explain -- Show all rules with descriptions

python3 scripts/vite_config_validator.py explain vite.config.json
python3 scripts/vite_config_validator.py explain vite.config.json --format json

suggest -- Run validation and propose fixes

python3 scripts/vite_config_validator.py suggest vite.config.json
python3 scripts/vite_config_validator.py suggest vite.config.json --format json

Flags

FlagDescription
-------------------
--strictTreat warnings as errors -- exit code 1 (CI-friendly)
--format textHuman-readable output (default)
--format jsonMachine-readable JSON
--format summaryCompact summary with counts

Validation Rules (25)

Structure (5)

RuleSeverityDescription
-----------------------------
S1errorFile not found or unreadable
S2errorEmpty config file
S3errorInvalid JSON syntax
S4warningUnknown top-level keys (not in Vite's valid config options)
S5infodefineConfig() wrapper hint (cannot verify in JSON export)

Build (5)

RuleSeverityDescription
-----------------------------
B1infoMissing build.outDir (defaults to 'dist')
B2errorInvalid build.target value
B3errorInvalid build.minify value (not boolean, 'terser', or 'esbuild')
B4warningbuild.sourcemap set to 'hidden' in development mode
B5warningDeprecated Rollup plugins (rollup-plugin- vs @rollup/plugin-)

Server (4)

RuleSeverityDescription
-----------------------------
V1error/warningserver.port out of valid range or privileged port
V2warningserver.host set to true/0.0.0.0 (security: exposes to network)
V3warningserver.proxy with invalid target URLs
V4warningserver.https without cert/key paths

Resolve (3)

RuleSeverityDescription
-----------------------------
R1warningresolve.alias with absolute paths (portability risk)
R2infoMissing resolve.extensions for TypeScript projects
R3warningresolve.dedupe with empty array

CSS (3)

RuleSeverityDescription
-----------------------------
C1infocss.preprocessorOptions without corresponding preprocessor dependency hint
C2warningcss.modules with invalid or unknown options
C3warningcss.postcss pointing to non-existent file

Plugins (2)

RuleSeverityDescription
-----------------------------
P1infoEmpty plugins array
P2warningDeprecated Vite plugin names

Best Practices (3)

RuleSeverityDescription
-----------------------------
X1infoNo mode set in config
X2infoMissing base path for non-root deployments
X3warningbuild.chunkSizeWarningLimit too high (>2000 kB)

Exit Codes

CodeMeaning
---------------
0No errors (warnings allowed unless --strict)
1Errors found (or warnings in --strict mode)
2File not found / parse error

CI Integration

# GitHub Actions
- name: Validate Vite config
  run: |
    node -e "import('./vite.config.ts').then(m => console.log(JSON.stringify(m.default)))" > /tmp/vite.config.json
    python3 scripts/vite_config_validator.py validate /tmp/vite.config.json --strict --format json

Example Output

vite.config validate -- vite.config.json
=========================================
[ERROR  ] B2: Invalid build.target value: 'ie11'
         Valid targets: 'modules', 'esnext', 'es20XX', or browser versions like 'chrome87', 'firefox78', 'safari13'.
[WARNING] V2: server.host exposes dev server to all network interfaces
         Setting host to true or '0.0.0.0' makes the dev server accessible from any device on the network. Use 'localhost' or '127.0.0.1' for local-only.
[WARNING] X3: build.chunkSizeWarningLimit is very high (5000 kB)
         A limit above 2000 kB effectively silences chunk size warnings. Large chunks hurt load performance. Consider code splitting instead of raising the limit. Default is 500 kB.
[INFO   ] S5: JSON export cannot verify defineConfig() wrapper
         Wrap your config with defineConfig() in vite.config.ts for type safety and IDE autocompletion: export default defineConfig({ ... })
[INFO   ] X1: No mode set in config
         Vite defaults to 'development' for serve and 'production' for build. Set mode explicitly if you need environment-specific behavior in the config itself.

Result: INVALID
Summary: 1 error(s), 2 warning(s), 2 info

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 08:03 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 196 📥 67,886
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 75 📥 182,312
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 681 📥 328,940