vite.config.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {defineConfig} from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import {createHtmlPlugin} from 'vite-plugin-html'
  4. import Components from 'unplugin-vue-components/vite'
  5. import {AntDesignVueResolver} from 'unplugin-vue-components/resolvers'
  6. import {themePreprocessorPlugin, themePreprocessorHmrPlugin} from "@zougt/vite-plugin-theme-preprocessor";
  7. import { fileURLToPath, URL } from "url"
  8. import path from 'path'
  9. // https://vitejs.dev/config/
  10. export default defineConfig({
  11. resolve: {
  12. alias: {
  13. "@": fileURLToPath(new URL("./src", import.meta.url)),
  14. },
  15. extensions: [
  16. '.mjs',
  17. '.js',
  18. '.ts',
  19. '.jsx',
  20. '.tsx',
  21. '.json',
  22. '.vue',
  23. '.less'
  24. ]
  25. },
  26. plugins: [vue(),
  27. Components({
  28. resolvers: [AntDesignVueResolver({importStyle: false})]
  29. }),
  30. themePreprocessorPlugin({
  31. less: {
  32. multipleScopeVars: [
  33. {
  34. scopeName: "theme-default",
  35. path: path.resolve("./src/style.less"),
  36. },
  37. {
  38. scopeName: "theme-dark",
  39. path: path.resolve("./src/dark.less"),
  40. },
  41. ],
  42. // css中不是由主题色变量生成的颜色,也让它抽取到主题css内,可以提高权重
  43. includeStyleWithColors: [
  44. {
  45. color: "#ffffff",
  46. // 排除属性
  47. // excludeCssProps:["background","background-color"]
  48. // 排除选择器
  49. // excludeSelectors: [
  50. // ".ant-btn-link:hover, .ant-btn-link:focus, .ant-btn-link:active",
  51. // ],
  52. },
  53. {
  54. color: ["transparent","none"],
  55. },
  56. ],
  57. },
  58. }),
  59. themePreprocessorHmrPlugin(),
  60. createHtmlPlugin({
  61. minify: true,
  62. /**
  63. * After writing entry here, you will not need to add script tags in `index.html`, the original tags need to be deleted
  64. * @default src/main.ts
  65. */
  66. entry: 'src/main.ts',
  67. /**
  68. * If you want to store `index.html` in the specified folder, you can modify it, otherwise no configuration is required
  69. * @default index.html
  70. */
  71. template: 'index.html',
  72. /**
  73. * Data that needs to be injected into the index.html ejs template
  74. */
  75. inject: {
  76. data: {
  77. title: 'Nginx UI',
  78. },
  79. },
  80. }),
  81. ],
  82. css: {
  83. preprocessorOptions: {
  84. less: {
  85. javascriptEnabled: true,
  86. }
  87. },
  88. },
  89. server: {
  90. proxy: {
  91. '/api': {
  92. target: 'https://nginx.jackyu.cn/',
  93. changeOrigin: true,
  94. secure: false,
  95. ws: true,
  96. },
  97. },
  98. },
  99. })