vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import vue from "@vitejs/plugin-vue";
  2. import { resolve } from "path";
  3. import { defineConfig, loadEnv, UserConfig, UserConfigExport } from "vite";
  4. import { createHtmlPlugin } 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. createHtmlPlugin({
  25. minify: true,
  26. /**
  27. * 需要注入 index.html ejs 模版的数据
  28. */
  29. inject: {
  30. data: {
  31. apiURL: loadEnv(mode, process.cwd()).VITE_APP_API,
  32. socketURL: loadEnv(mode, process.cwd()).VITE_APP_SOCKET,
  33. title: ""
  34. },
  35. tags: [
  36. {
  37. injectTo: 'body-prepend',
  38. tag: 'div',
  39. attrs: {
  40. id: 'tag'
  41. }
  42. }
  43. ]
  44. }
  45. }),
  46. tsconfigPaths(),
  47. createSvgIconsPlugin({
  48. iconDirs: [resolve(__dirname, "src/assets/icons/svg")],
  49. symbolId: "icon-[dir]-[name]"
  50. })
  51. ],
  52. build: {
  53. chunkSizeWarningLimit: 1024,
  54. commonjsOptions: {
  55. include: /node_modules|lib/
  56. },
  57. rollupOptions: {
  58. output: {
  59. manualChunks: {
  60. monacoeditor: ["monaco-editor"],
  61. quill: ["quill"],
  62. lodash: ["lodash"],
  63. lib: ["sortablejs", "vxe-table", "xe-utils"],
  64. vlib: ["vue", "vue-router", "vue-i18n", "element-plus"]
  65. }
  66. }
  67. }
  68. },
  69. resolve: {
  70. alias: {
  71. // 配置别名
  72. "@": resolve(__dirname, "./src"),
  73. "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
  74. }
  75. },
  76. server: {
  77. open: false, // 自动启动浏览器
  78. host: "0.0.0.0", // localhost
  79. port: 8001, // 端口号
  80. hmr: { overlay: false }
  81. }
  82. });
  83. };