55 lines
801 B
Markdown
55 lines
801 B
Markdown
**初始化项目**
|
|
```shell
|
|
npm init -y
|
|
```
|
|
**安装vite (开发依赖)**
|
|
```shell
|
|
npm add -D vite
|
|
```
|
|
**运行 vite 项目**
|
|
```shell
|
|
npx vite
|
|
```
|
|
**打包 vite 项目**
|
|
```shell
|
|
npx vite build
|
|
```
|
|
**启动预览服务器**
|
|
```shell
|
|
npx vite preview
|
|
```
|
|
|
|
此外可以使用命令一键创建 vite 项目模板
|
|
```shell
|
|
npm create vite@latest
|
|
```
|
|
|
|
在 vite.config.js 中配置插件
|
|
|
|
**添加插件**
|
|
```shell
|
|
npm add -D @vitejs/plugin-legacy
|
|
```
|
|
**配置插件**
|
|
```shell
|
|
// vite.config.js
|
|
import image from '@rollup/plugin-image'
|
|
import { defineConfig } from 'vite'
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
{
|
|
...image(),
|
|
enforce: 'pre',
|
|
},
|
|
],
|
|
})
|
|
```
|
|
**配置vite**
|
|
```shell
|
|
import { defineConfig } from 'vite'
|
|
const config = defineConfig({
|
|
|
|
})
|
|
export default config
|
|
``` |