1、vite + vue3 + ts 如何使用别名
    只要修改以下两个文件 tsconfig.json + vite.config.js 就可以了!

    1. {
    2. "compilerOptions": {
    3. "baseUrl": ".",
    4. "paths": {
    5. "@/*": [
    6. "src/*"
    7. ],
    8. "@/components/*": [
    9. "src/components/*"
    10. ],
    11. "/@style/*": [
    12. "src/style/*"
    13. ],
    14. "/@views/*": [
    15. "src/views/*"
    16. ],
    17. "/@lib/*": [
    18. "src/lib/*"
    19. ]
    20. }
    21. },
    22. "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    23. "references": [{ "path": "./tsconfig.node.json" }]
    24. }
    1. import { defineConfig } from "vite"
    2. import vue from "@vitejs/plugin-vue"
    3. import pxtorem from "postcss-pxtorem"
    4. import path from "path";
    5. const { resolve } = require("path");
    6. export default defineConfig({
    7. base: "./", // 开发或生产环境服务的 公共基础路径
    8. resolve: {
    9. alias: {
    10. "/@": resolve(__dirname, "./src"),
    11. "/@style": resolve(__dirname, "./src/style"),
    12. "/@views": resolve(__dirname, "./src/views"),
    13. "/@components": resolve(__dirname, "./src/components"),
    14. "/@lib": resolve(__dirname, "./src/libs"),
    15. },
    16. },
    17. css: {
    18. //css预处理
    19. preprocessorOptions: {
    20. scss: {
    21. charset: false,
    22. //引入var.scss全局预定义变量
    23. additionalData:
    24. '@import "./src/style/mixins.scss";@import "./src/style/variable.scss";',
    25. },
    26. },
    27. },
    28. plugins: [
    29. vue(),
    30. pxtorem({
    31. rootValue: 37.5,
    32. unitPrecision: 4, // 保留小数位
    33. propList: ["*"],
    34. // selectorBlackList: [''], //过滤的类名
    35. replace: true, // 默认直接替换属性
    36. mediaQuery: false,
    37. minPixelValue: 6, // 所有小于设置的样式都不被转换
    38. }),
    39. ],
    40. server: {
    41. host: "0.0.0.0",
    42. fs: {
    43. // Allow serving files from one level up to the project root
    44. allow: [".."],
    45. },
    46. port: 3000,
    47. },
    48. })