vite.config.js 930 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { defineConfig } from "vite";
  2. import { createVuePlugin } from "vite-plugin-vue2";
  3. import svgLoader from "vite-plugin-vue2-svg";
  4. // 1. 导入 CommonJS 转换插件
  5. import commonjs from "vite-plugin-commonjs";
  6. import path from "path";
  7. export default defineConfig({
  8. base: "./",
  9. plugins: [
  10. createVuePlugin(),
  11. svgLoader,
  12. // 2. 添加插件,转换 CommonJS 语法
  13. commonjs({
  14. // 配置需要转换的文件范围
  15. include: [/src\/assets\/images\//, /node_modules/],
  16. }),
  17. ],
  18. resolve: {
  19. alias: {
  20. "@": path.resolve(__dirname, "./src"),
  21. },
  22. extensions: [".vue", ".js", ".json", ".less"],
  23. },
  24. server: {
  25. port: 8080, // 保持与 Vue CLI 相同的端口
  26. open: true, // 启动时自动打开浏览器
  27. cors: true,
  28. },
  29. css: {
  30. preprocessorOptions: {
  31. less: {
  32. // 配置 Less 全局变量等
  33. javascriptEnabled: true,
  34. },
  35. },
  36. },
  37. });