.fes.predev.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * @Description:
  3. * @Version: 1.668
  4. * @Autor: 地虎降天龙
  5. * @Date: 2023-10-16 10:53:09
  6. * @LastEditors: 地虎降天龙
  7. * @LastEditTime: 2026-06-01 16:00:37
  8. */
  9. import { defineBuildConfig } from '@fesjs/fes'
  10. import { readFileSync } from 'node:fs'
  11. import { posix } from 'node:path'
  12. import fg from 'fast-glob'
  13. // import viteCompression from 'vite-plugin-compression'
  14. import javascriptObfuscator from 'vite-plugin-javascript-obfuscator'
  15. import addExtraScriptPlugin from './src/common/addExtraScriptPlugin.js'
  16. const PLUGIN_SOURCE_GLOB = '**/*.{vue,js,ts,jsx,tsx}'
  17. const pluginPredevEntries = fg.sync('src/plugins/*/predev.config.json').flatMap((configFile) => {
  18. const { sources = [] } = JSON.parse(readFileSync(configFile, 'utf8'))
  19. return sources.map((source) => posix.join(posix.dirname(configFile), source, PLUGIN_SOURCE_GLOB))
  20. })
  21. function scanPluginSources(entries) {
  22. return {
  23. name: 'predev-scan-plugin-sources',
  24. apply: 'serve',
  25. async configResolved(config) {
  26. const unoContext = config.plugins
  27. .find((plugin) => plugin.name === 'unocss:api')
  28. ?.api?.getContext()
  29. if (!unoContext || !entries.length) return
  30. // 在页面打开前完成插件样式扫描,避免首次懒加载触发 UnoCSS 全局热更新。
  31. const unoConfig = await unoContext.getConfig()
  32. unoConfig.content = {
  33. ...unoConfig.content,
  34. filesystem: [...(unoConfig.content?.filesystem || []), ...entries],
  35. }
  36. },
  37. }
  38. }
  39. export default defineBuildConfig({
  40. layout: {
  41. title: 'TvT.js',
  42. navigation: 'top',
  43. multiTabs: false,
  44. isFixedHeader: true,
  45. logo: 'logo.png',
  46. menus: [
  47. {
  48. name: 'preview',
  49. path: '/',
  50. title: '📀 预览演示',
  51. },
  52. {
  53. path: 'https://gitee.com/ice-gl/icegl-three-vue-tres',
  54. title: '📜 源码地址',
  55. },
  56. {
  57. title: '📚 说明文档',
  58. children: [
  59. {
  60. path: 'http://docs.icegl.cn',
  61. title: '🧊 TvT框架文档',
  62. },
  63. {
  64. path: 'https://threejs.org/docs/index.html#manual/zh/introduction/Creating-a-scene',
  65. title: '🎲 three.js',
  66. },
  67. {
  68. path: 'https://tresjs.org/guide/',
  69. title: '⚡ tres.js',
  70. },
  71. {
  72. path: 'https://fesjs.mumblefe.cn/',
  73. title: '💠 fes.js',
  74. },
  75. ],
  76. },
  77. {
  78. path: 'https://www.bilibili.com/video/BV1LH4y1p7Yn',
  79. title: '📀 TvT视频教程',
  80. },
  81. {
  82. path: 'https://www.icegl.cn/tvtstore',
  83. title: '🧩 插件市场',
  84. },
  85. {
  86. title: '🪢 编辑器生态',
  87. children: [
  88. {
  89. path: 'https://dcser.icegl.cn',
  90. title: '🪡 动态组件服务',
  91. },
  92. {
  93. path: 'https://zone3deditor.icegl.cn/#/plugins/zone3Deditor/index',
  94. title: '🖼️ 区域场景编辑器',
  95. },
  96. {
  97. path: 'https://gisplaneeditor.icegl.cn/#/plugins/gisPlaneEditor/index',
  98. title: '🗺️ GIS地理空间编辑器',
  99. },
  100. {
  101. path: 'https://animationeditor.icegl.cn/#/plugins/animationEditor/index',
  102. title: '🐛 草履虫动画编辑器',
  103. },
  104. {
  105. path: 'https://materialeditor.icegl.cn/#/plugins/materialEditor/index',
  106. title: '🎨 材质编辑器',
  107. },
  108. ],
  109. },
  110. {
  111. title: '🧊 ICEGL官网社区',
  112. children: [
  113. {
  114. path: 'https://www.icegl.cn/',
  115. title: '🧊 ICEGL官网',
  116. },
  117. {
  118. path: 'https://www.icegl.cn/ask',
  119. title: '🙋‍♀️ 社区问答',
  120. },
  121. ],
  122. },
  123. {
  124. title: '👨‍🏫 课程中心',
  125. children: [
  126. {
  127. path: 'https://icegl.cn/courses',
  128. title: '🌁 WebGL初/中/高级教程',
  129. },
  130. {
  131. path: 'https://www.bilibili.com/video/BV1iR4y1C7LQ/',
  132. title: '🏙 WebGL Shader初级教程',
  133. },
  134. {
  135. path: 'http://m.study.163.com/provider/480000002303414/index.htm?share=2&shareId=480000002303414',
  136. title: '🌇 WebGL Shader中级教程',
  137. },
  138. ],
  139. },
  140. {
  141. path: 'https://www.icegl.cn/tvtstore/uniAppView',
  142. title: '🪅 小程序生态',
  143. },
  144. {
  145. path: 'https://www.icegl.cn/d/demand/post',
  146. title: '🪢 定制开发',
  147. },
  148. {
  149. path: 'https://www.icegl.cn/p/tvtdeveloper.html',
  150. title: '💫 加入我们',
  151. },
  152. ],
  153. },
  154. viteOption: {
  155. optimizeDeps: {
  156. entries: ['index.html', ...pluginPredevEntries],
  157. },
  158. plugins: [
  159. console.log('正在加载 TvT.js...'),
  160. scanPluginSources(pluginPredevEntries),
  161. addExtraScriptPlugin(),
  162. ],
  163. server: {
  164. proxy: {
  165. // 开发代理服务器配置
  166. '/api.icegl': {
  167. target: 'https://www.icegl.cn/',
  168. changeOrigin: true,
  169. rewrite: (path) => path.replace(/^\/api.icegl/, ''),
  170. },
  171. // 天地图本地代理
  172. '/tianditu.map': {
  173. target: 'https://t0.tianditu.gov.cn/',
  174. changeOrigin: true,
  175. headers: {
  176. Origin: 'opensource.icegl.cn',
  177. Referer: 'http://opensource.icegl.cn',
  178. },
  179. rewrite: (path) => path.replace(/^\/tianditu.map/, ''),
  180. }
  181. },
  182. },
  183. build:{
  184. reportCompressedSize: false,
  185. cssMinify: false,
  186. minify: 'esbuild',
  187. }
  188. },
  189. })