.fes.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * @Description:
  3. * @Version: 1.668
  4. * @Autor: 地虎降天龙
  5. * @Date: 2023-10-16 10:53:09
  6. * @LastEditors: 地虎降天龙
  7. * @LastEditTime: 2025-12-31 11:44:50
  8. */
  9. // import { resolve } from 'path';
  10. import { join, dirname } from 'path'
  11. import { fileURLToPath } from 'url'
  12. import { defineBuildConfig } from '@fesjs/fes'
  13. import { templateCompilerOptions } from '@tresjs/core'
  14. // eslint-disable-next-line import/no-unresolved
  15. import UnoCSS from 'unocss/vite'
  16. // eslint-disable-next-line import/no-extraneous-dependencies
  17. import glsl from 'vite-plugin-glsl'
  18. import federation from '@originjs/vite-plugin-federation'
  19. import cesiumStatic from './src/common/cesiumStaticPlugin.js'
  20. import localGisStatic from './src/common/localGisStaticPlugin.js'
  21. import { vendoredPluginLibAliases } from './src/common/vendoredPluginLibAliases.js'
  22. const __filename = fileURLToPath(import.meta.url);
  23. const __dirname = dirname(__filename);
  24. const timeStamp = new Date().getTime()
  25. const combinedIsCustomElement = (tag) => tag.startsWith('iconify-icon') || templateCompilerOptions.template.compilerOptions.isCustomElement(tag)
  26. export default defineBuildConfig({
  27. mountElementId: 'tvt-app',
  28. title: 'TvT.js',
  29. publicPath: './', // './' 若在线部署用于生产环境 且 是使用qiankun微前端时,需要配置base为主应用地址 https://cos.icegl.cn/qiankun/tvt/
  30. access: {
  31. roles: {
  32. admin: ['*'],
  33. manager: ['/'],
  34. },
  35. },
  36. layout: {
  37. navigation: null,
  38. },
  39. enums: {
  40. status: [
  41. ['0', '无效的'],
  42. ['1', '有效的'],
  43. ],
  44. },
  45. qiankun: {
  46. micro: {
  47. useDevMode: true,
  48. },
  49. },
  50. //add by 地虎降天龙
  51. viteVuePlugin: {
  52. template: {
  53. compilerOptions: {
  54. isCustomElement: (tag) => combinedIsCustomElement(tag),
  55. },
  56. },
  57. },
  58. viteOption: {
  59. plugins: [
  60. UnoCSS({
  61. /* options */
  62. }),
  63. glsl({
  64. warnDuplicatedImports: false, // 禁用重复导入警告
  65. }),
  66. federation({
  67. name: 'tvt-host',
  68. remotes: {
  69. home: {
  70. // 必须默认引用一个 不然会报错:ReferenceError: __rf_placeholder__shareScope is not defined
  71. external: `Promise.resolve('https://dcser.icegl.cn/assets/remoteEntry.js')`,
  72. externalType: "promise"
  73. }
  74. },
  75. shared: {
  76. vue: {},
  77. three: { version: '0.180.0' },
  78. // "@tresjs/cientos": { version: '5.2.0' },
  79. // "@tresjs/core": { version: '5.2.0' },
  80. // three: { import: false, generate: false }
  81. }
  82. // 票27:cesium 不进 shared —— 远程不需要它,且体积大、CESIUM_BASE_URL 是进程级单例。
  83. }),
  84. // 票27:把 cesium 预构建静态资源接到 <base>/cesium/(dev 中间件 + build 拷贝)。
  85. cesiumStatic(),
  86. // 票21:把本机/甲方的 GIS 目录(DEM、影像切片)挂成静态路径,目录由 .env.local 的
  87. // COCKPIT_GIS_MOUNTS 给;没配就什么也不挂,别的机器照常跑。
  88. localGisStatic()
  89. ],
  90. build: {
  91. target: 'esnext', // 或者 'es2020' 以支持 BigInt
  92. chunkSizeWarningLimit: 1000, // 单位为KB
  93. rollupOptions: {
  94. output: {
  95. minifyInternalExports: false,
  96. manualChunks: {
  97. three: ['three'],
  98. '3d-tiles-renderer': ['3d-tiles-renderer'],
  99. cesium: ['cesium'], // 票27:引擎单独分包
  100. },
  101. // manualChunks (id) {
  102. // // 自定义拆分策略,例如将特定的第三方库拆分为单独的 chunk
  103. // if (id.includes('node_modules')) {
  104. // const texts = id.toString().split('node_modules/')[1].split('/')[0]
  105. // // if (texts) {
  106. // // console.log(id.toString(), texts)
  107. // // }
  108. // return texts
  109. // }
  110. // },
  111. format: 'es',
  112. chunkFileNames: `js/[name].[hash]${timeStamp}.js`,
  113. entryFileNames: `js/[name].[hash]${timeStamp}.js`,
  114. assetFileNames: `[ext]/[name].[hash]${timeStamp}.[ext]`,
  115. name: 'TvT.js',
  116. },
  117. },
  118. sourcemap: false,
  119. minify: 'terser',
  120. },
  121. // 全局 css 注册
  122. css: {
  123. preprocessorOptions: {
  124. scss: {
  125. // javascriptEnabled: true,
  126. // additionalData: `@import "src/plugins/goView/lib/scss/style.scss";`,
  127. additionalData: (content, filename) => {
  128. if (filename.includes('src/plugins/goView') || filename.includes('src/plugins/zone3Deditor')) {
  129. return `@import "src/plugins/goView/lib/scss/style.scss";\n${content}`
  130. }
  131. return content
  132. }
  133. },
  134. },
  135. },
  136. server: {
  137. headers: {
  138. 'Access-Control-Allow-Origin': '*',
  139. },
  140. host: '0.0.0.0',
  141. // 票26:面板与 DSH 的原子写临时文件在 Windows 上都会让 chokidar 抛 EBUSY 击穿 dev server。
  142. // `**/.scratch/**` → issue tracker 面板保存单据时的 .tmpdir 原子写
  143. // `**/.dsh-*` → DSH 每次编辑文件时在项目根生成的 .dsh-edit-review.json.<pid>.<guid>.tmpdir
  144. // `**/*.tmpdir/**` → 票27 实测:同一类原子写临时目录这次落在**源码目录旁**
  145. // (src/modules/cockpit/components/.MapCanvas.vue.<pid>.<guid>.tmpdir),
  146. // 前两条都盖不住,pre.dev.one 首次启动被击穿。按模式排除,别只堵已知的那一个路径。
  147. // Vite 内部默认 ignore(node_modules/.git/cacheDir 等)与此合并而非覆盖,见 vite resolveChokidarOptions。
  148. watch: {
  149. // 目录本身与目录内容要分别盖住:chokidar 对目录条目的匹配和对其内容的匹配是两条判断,
  150. // 只写 `**/*.tmpdir/**` 时那个目录本身仍会被进入,读它时照样 EBUSY。
  151. ignored: ['**/.scratch/**', '**/.dsh-*', '**/*.tmpdir', '**/*.tmpdir/**'],
  152. },
  153. proxy: {
  154. '/resource.cos': {
  155. target: 'https://opensource.cdn.icegl.cn',
  156. changeOrigin: true,
  157. rewrite: (path) => path.replace(/^\/resource.cos/, ''),
  158. },
  159. // 天地图本地代理
  160. '/tianditu.map': {
  161. target: 'https://t0.tianditu.gov.cn/',
  162. changeOrigin: true,
  163. headers: {
  164. Origin: 'opensource.icegl.cn',
  165. Referer: 'http://opensource.icegl.cn',
  166. },
  167. rewrite: (path) => path.replace(/^\/tianditu.map/, ''),
  168. }
  169. },
  170. },
  171. },
  172. alias: {
  173. // 插件自带的依赖副本(src/plugins/<插件>/lib/<包>)指回插件内部:
  174. // useThreeGeospatial 用的 @takram/three-3d-tiles-support 等包没有发布到 npm,
  175. // 不映射的话 yarn build 会直接在这些 import 上失败。
  176. ...vendoredPluginLibAliases(join(__dirname, './src/plugins'), join(__dirname, './node_modules')),
  177. PLS: join(__dirname, './src/plugins'),
  178. },
  179. // { find: 'pls', replacement: resolve(__dirname, './src/plugins') },
  180. // { '@': join(__dirname, '/src') }
  181. })