vite.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import vue from "@vitejs/plugin-vue";
  2. import { resolve } from "path";
  3. import { defineConfig, loadEnv, UserConfig, UserConfigExport } from "vite";
  4. import html from "vite-plugin-html";
  5. import tsconfigPaths from "vite-tsconfig-paths";
  6. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  7. const prefix = `monaco-editor/esm/vs`;
  8. export default (config: UserConfig): UserConfigExport => {
  9. const mode = config.mode as string;
  10. return defineConfig({
  11. base: "./",
  12. optimizeDeps: {
  13. include: [
  14. `${prefix}/language/json/json.worker`,
  15. `${prefix}/language/css/css.worker`,
  16. `${prefix}/language/html/html.worker`,
  17. `${prefix}/language/typescript/ts.worker`,
  18. `${prefix}/editor/editor.worker`,
  19. "@/../lib/vform/designer.umd.js"
  20. ]
  21. },
  22. plugins: [
  23. vue(),
  24. html({
  25. inject: {
  26. injectData: {
  27. apiURL: loadEnv(mode, process.cwd()).VITE_APP_API,
  28. socketURL: loadEnv(mode, process.cwd()).VITE_APP_SOCKET,
  29. title: ""
  30. }
  31. },
  32. minify: true
  33. }),
  34. tsconfigPaths(),
  35. createSvgIconsPlugin({
  36. iconDirs: [resolve(__dirname, "src/assets/icons/svg")],
  37. symbolId: "icon-[dir]-[name]"
  38. })
  39. ],
  40. build: {
  41. chunkSizeWarningLimit: 1024,
  42. commonjsOptions: {
  43. include: /node_modules|lib/
  44. },
  45. rollupOptions: {
  46. output: {
  47. manualChunks: {
  48. monacoeditor: ["monaco-editor"],
  49. quill: ["quill"],
  50. lodash: ["lodash"],
  51. lib: ["sortablejs", "vxe-table", "xe-utils"],
  52. vlib: ["vue", "vue-router", "vue-i18n", "element-plus"]
  53. }
  54. }
  55. }
  56. },
  57. resolve: {
  58. alias: {
  59. // 配置别名
  60. "@": resolve(__dirname, "./src"),
  61. "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
  62. }
  63. },
  64. server: {
  65. open: false, // 自动启动浏览器
  66. host: "0.0.0.0", // localhost
  67. port: 8001, // 端口号
  68. https: false,
  69. hmr: { overlay: false }
  70. }
  71. });
  72. };