vite.config.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import react from '@vitejs/plugin-react-swc';
  2. import UnoCSS from 'unocss/vite';
  3. import { defineConfig, loadEnv, PluginOption } from 'vite';
  4. import pluginImport from 'vite-plugin-importer';
  5. import svgr from 'vite-plugin-svgr';
  6. import tsconfigPaths from 'vite-tsconfig-paths';
  7. /// <reference types="vite-plugin-svgr/client" />
  8. // https://vite.dev/config/
  9. export default defineConfig(({ mode }) => {
  10. const config = loadEnv(mode, './');
  11. return {
  12. resolve: {
  13. alias: [],
  14. },
  15. plugins: [
  16. svgr() as PluginOption,
  17. react(),
  18. UnoCSS(),
  19. pluginImport({
  20. libraryName: '@nutui/nutui-react',
  21. libraryDirectory: 'dist/esm',
  22. style: (path: string) => `${path}/style/css`,
  23. }),
  24. tsconfigPaths() as PluginOption,
  25. ],
  26. css: {
  27. // modules: {
  28. // hashPrefix: 'prefix',
  29. // generateScopedName: '[name]__[local]__[hash:base64:5]',
  30. // },
  31. preprocessorOptions: {
  32. sass: {
  33. api: 'modern',
  34. additionalData: `@nutui/nutui-react/dist/styles/variables.scss`,
  35. silenceDeprecations: ['legacy-js-api', 'color-functions'],
  36. },
  37. scss: {
  38. api: 'modern',
  39. silenceDeprecations: ['legacy-js-api'],
  40. },
  41. },
  42. },
  43. server: {
  44. proxy: {
  45. '/api': {
  46. target: config.VITE_BASIC_URL,
  47. changeOrigin: true,
  48. secure: false,
  49. },
  50. },
  51. },
  52. };
  53. });