- 创建vite工程,需要nodejs >= 12.0
npm init @vitejs/app
查看package.json
...
"scripts": {
"dev": "vite --port 8080", // 还可以加上 --https
"build": "vue-tsc --noEmit && vite build",
"serve": "vite preview",
"preview": "vite preview"
},
...
加入scss或less… ```json
.scss and .sass
npm install -D sass
.less
npm install -D less
.styl and .stylus
npm install -D stylus
4. npm run build 丝滑体验
```json
npm run build // 会生成dist文件夹
npm run preview // 启动本地应用测试,访问dist里面的文件
- 多页面配置 rollup配置 ```json import { defineConfig } from ‘vite’ import vue from ‘@vitejs/plugin-vue’ const path = require(‘path’); const { resolve } = path; console.log(dirname) // https://vitejs.dev/config/ export default defineConfig({ resolve: { extensions: [‘.vue’, ‘.js’, ‘.ts’, ‘.tsx’], alias: [ { find: ‘@’, replacement: dirname }, ], }, // build: { // // build rollup的配置 // rollupOptions: { // // https://rollupjs.org/guide/en/#big-list-of-options // // 多页面的配置 // input: { // main: resolve(dirname, ‘index.html’), // // nested: resolve(dirname, ‘nested/index.html’) // } // } // }, plugins: [vue()] })
```
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"typeRoots": ["./types"],
"baseUrl": ".",
"paths": {
"@/*": [ "./*" ]
},
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"utils/**/*.ts",
"node_modules/element-ui/packages/**/*.js"
]
}