Open Harvey-Andrew opened 1 week ago
控制台
App.vue
uni.scss
tsconfig.json
{ "compilerOptions": { "target": "esnext", "useDefineForClassFields": true, "module": "esnext", "moduleResolution": "node", "strict": true, "jsx": "preserve", "sourceMap": true, "resolveJsonModule": true, "esModuleInterop": true, "lib": ["esnext", "dom"], "types": ["@dcloudio/types", "vite/client", "@types/node", "nutui-uniapp/global.d.ts"], "baseUrl": "./src", "paths": { "@/*": ["*"], "@components/*": ["src/components/*"] }, "ignoreDeprecations": "5.0", "suppressImplicitAnyIndexErrors": true, "allowJs": true, // 对声明文件不进行类型检查 "skipLibCheck": true }, //加入配置,将标签视为原始组件 "vueCompilerOptions": { "nativeTags": ["block", "component", "template", "slot"] }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] }
vite.config.ts
import { defineConfig, loadEnv } from 'vite' import uni from '@dcloudio/vite-plugin-uni' import path from 'path' import fs from 'fs-extra' import Components from '@uni-helper/vite-plugin-uni-components' import { NutResolver } from 'nutui-uniapp' // https://vitejs.dev/config/ export default defineConfig(async ({ mode }) => { // 根据当前工作目录中的 `mode` 加载 .env 文件 // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。 // "dev:mp-weixin:student": "uni -p mp-weixin -m studentDev", pnpm run dev:mp-weixin:student const env = loadEnv(mode, `${process.cwd()}/env`, '') await fs.copy(path.resolve(__dirname, env.VITE_APP_BUILD_CONFIG), path.join(__dirname, 'src')) return { plugins: [ Components({ resolvers: [NutResolver()], }), uni(), ], resolve: { alias: { '@': path.resolve(__dirname, './src'), '@components': path.resolve(__dirname, './src/components'), }, }, css: { // 配置`scss`和`less`全局变量 preprocessorOptions: { scss: { additionalData: '@import "nutui-uniapp/styles/variables.scss";', }, less: { additionalData: '@import "@/styles/vars/_base.less";', }, }, }, envDir: path.resolve(__dirname, 'env'), } })
控制台
App.vue
uni.scss
tsconfig.json
vite.config.ts