.fes.js 7.7 KB

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