vite.config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import path from 'path';
  2. import { UserConfigExport, ConfigEnv } from 'vite';
  3. import vueJsx from '@vitejs/plugin-vue-jsx';
  4. import vue from '@vitejs/plugin-vue';
  5. import svgLoader from 'vite-svg-loader';
  6. import Components from 'unplugin-vue-components/vite';
  7. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
  8. import ElementPlus from 'unplugin-element-plus/vite';
  9. /**
  10. * @type {import('vite').UserConfig}
  11. * @link {https://vitejs.cn/config/}
  12. */
  13. export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  14. console.log(command);
  15. return {
  16. root: process.cwd(),
  17. base: './',
  18. server: {
  19. host: 'localhost',
  20. open: true,
  21. port: 8000,
  22. // strictPort: true,
  23. https: false,
  24. force: true,
  25. proxy: {
  26. '/api': {
  27. target: 'http://api.xt.wenhq.top:8083/mock/43',
  28. changeOrigin: true,
  29. rewrite: (path) => path.replace(/^\/api/, ''),
  30. },
  31. },
  32. },
  33. resolve: {
  34. alias: {
  35. '@': path.resolve(__dirname, './src'),
  36. },
  37. },
  38. css: {
  39. modules: {
  40. localsConvention: 'camelCase', // 默认只支持驼峰,修改为同事支持横线和驼峰
  41. },
  42. preprocessorOptions: {
  43. scss: {
  44. /**
  45. * TODO:// 目前按需加载时修改主题色会报错
  46. * 官方修复后在进行按需加载
  47. * @link {https://github.com/element-plus/element-plus/issues/2724}
  48. *
  49. * */
  50. // additionalData: `@use "@/styles/element/index.scss" as *;`,
  51. },
  52. // scss: { additionalData: `@import "@/styles/vars.scss";` },
  53. // less: {
  54. // javascriptEnabled: true,
  55. // additionalData: `@import "@/styles/default.less";`,
  56. // },
  57. },
  58. },
  59. plugins: [
  60. vue(),
  61. vueJsx({
  62. // options are passed on to @vue/babel-plugin-jsx
  63. }),
  64. svgLoader(),
  65. // ElementPlus({ useSource: true }),
  66. ],
  67. };
  68. };