vite.config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { defineConfig, normalizePath } from "vite";
  2. import { fileURLToPath, URL } from "node:url";
  3. import vue from "@vitejs/plugin-vue";
  4. import vueJsx from "@vitejs/plugin-vue-jsx";
  5. import linaria from "@linaria/rollup";
  6. import css from "rollup-plugin-css-only";
  7. import WindiCSS from "vite-plugin-windicss";
  8. import Components from "unplugin-vue-components/vite";
  9. import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
  10. import { resolve } from "path";
  11. // https://vitejs.dev/config/
  12. export default defineConfig({
  13. base:
  14. process.env.NODE_ENV == "production"
  15. ? "//infishwaibao.oss-cn-chengdu.aliyuncs.com/xihuadesign/"
  16. : "./",
  17. build: {
  18. rollupOptions: {
  19. input: {
  20. index: resolve(__dirname, "./index.html"),
  21. admin: resolve(__dirname, "./admin.html"),
  22. },
  23. },
  24. },
  25. server: {
  26. host: "0.0.0.0",
  27. port: 8888,
  28. open: false,
  29. },
  30. plugins: [
  31. WindiCSS(),
  32. linaria({
  33. include: ["**/*.{ts,tsx}"],
  34. sourceMap: process.env.NODE_ENV !== "production",
  35. babelOptions: {
  36. presets: ["@babel/preset-typescript"],
  37. },
  38. }),
  39. // css({
  40. // output: (
  41. // styles: string,
  42. // styleNodes: Record<string, string>,
  43. // bundle: any
  44. // ) => {
  45. // console.log(bundle);
  46. // return "style.css";
  47. // },
  48. // }),
  49. Components({
  50. resolvers: [
  51. AntDesignVueResolver({
  52. // importLess: true
  53. }),
  54. ],
  55. }),
  56. vue(),
  57. vueJsx(),
  58. ],
  59. esbuild: {
  60. include: ["./src/**/*.tsx"],
  61. jsxInject: `import { getImageUrl } from '@/utils'`,
  62. },
  63. css: {
  64. preprocessorOptions: {
  65. less: {
  66. javascriptEnabled: true,
  67. modifyVars: {
  68. "primary-color": "#41969c",
  69. },
  70. },
  71. },
  72. },
  73. resolve: {
  74. alias: {
  75. "@": fileURLToPath(new URL("./src", import.meta.url)),
  76. },
  77. },
  78. });