Vite配置详解
Vite Config 详解
小贴士
npm run xxx
实际是执行 npx 命令的一个简写, 实际执行的命令记录在package.json
中.npx vite --debug
可以开启 vite 调试模式, 该模式会在终端输出当前的 vite 配置, 并输出调试信息.动态生成配置文件
大多情况下, 我们需要在开发 生产过程中使用不同的配置文件, 可以给
defineConfig
传入一个匿名函数来动态生成配置对象.1 2 3 4 5
export default defineConfig((command, mode)=>{ base: '/', plugins: [], server: {}, })
Command
Vite 有四个可执行命令:
vite (serve/dev)
: 启动开发服务器vite build
: 构建生产版本vite optimize
: 预构建依赖分析vite preview
: 本地预览构建产物 其中, vite 配置文件会影响 开发服务器 和 构建生产版本 两个过程. 配置文件中的command
就是这两种:serve build
分别代表开发和生产环境.
This post is licensed under CC BY 4.0 by the author.