vite.config.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defineConfig, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "node:path";
  4. import { createHtmlPlugin } from 'vite-plugin-html';
  5. import { version } from './package.json'
  6. // https://vite.dev/config/
  7. export default ({ mode }: any) => {
  8. const env = loadEnv(mode, process.cwd())
  9. return defineConfig({
  10. resolve: {
  11. alias: {
  12. "@/": `${path.resolve(__dirname, "src")}/`,
  13. },
  14. },
  15. css: {
  16. preprocessorOptions: {
  17. scss: {
  18. quietDeps: true,
  19. additionalData: `
  20. @forward 'element-plus/theme-chalk/src/common/var' with (
  21. $colors: (
  22. 'primary': (
  23. 'base': ${env.VITE_PRIMARY},
  24. ),
  25. ),
  26. );
  27. `,
  28. },
  29. },
  30. },
  31. server: {
  32. port: 9000,
  33. open: true,
  34. host: "0.0.0.0",
  35. },
  36. plugins: [
  37. createHtmlPlugin({
  38. template: 'index.html',
  39. entry: env.VITE_ENTRY,
  40. inject: {
  41. data: {
  42. title: env.VITE_TITLE,
  43. },
  44. }
  45. }),
  46. vue()
  47. ],
  48. define: {
  49. __VERSION__: JSON.stringify(version)
  50. }
  51. });
  52. };