@needle-tools/engine 5.1.0-canary.db0c38f → 5.1.0-canary.e7c2511

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/.needle/generated/needle-bindings.gen.d.ts +5 -0
  2. package/CHANGELOG.md +52 -0
  3. package/components.needle.json +1 -1
  4. package/dist/{needle-engine.bundle-B29kieh0.js → needle-engine.bundle-D-eWNCu1.js} +12287 -11802
  5. package/dist/needle-engine.bundle-D3ZUII8o.min.js +1733 -0
  6. package/dist/needle-engine.bundle-_rOpvUGL.umd.cjs +1733 -0
  7. package/dist/needle-engine.d.ts +833 -231
  8. package/dist/needle-engine.js +584 -582
  9. package/dist/needle-engine.min.js +1 -1
  10. package/dist/needle-engine.umd.cjs +1 -1
  11. package/lib/engine/api.d.ts +6 -1
  12. package/lib/engine/api.js +4 -0
  13. package/lib/engine/api.js.map +1 -1
  14. package/lib/engine/codegen/register_types.js +2 -10
  15. package/lib/engine/codegen/register_types.js.map +1 -1
  16. package/lib/engine/debug/debug_spatial_console.d.ts +2 -0
  17. package/lib/engine/debug/debug_spatial_console.js +10 -7
  18. package/lib/engine/debug/debug_spatial_console.js.map +1 -1
  19. package/lib/engine/engine_addressables.d.ts +2 -0
  20. package/lib/engine/engine_addressables.js +6 -3
  21. package/lib/engine/engine_addressables.js.map +1 -1
  22. package/lib/engine/engine_audio.d.ts +68 -0
  23. package/lib/engine/engine_audio.js +172 -0
  24. package/lib/engine/engine_audio.js.map +1 -1
  25. package/lib/engine/engine_components.js +1 -1
  26. package/lib/engine/engine_components.js.map +1 -1
  27. package/lib/engine/engine_context.d.ts +21 -20
  28. package/lib/engine/engine_context.js +27 -16
  29. package/lib/engine/engine_context.js.map +1 -1
  30. package/lib/engine/engine_disposable.d.ts +171 -0
  31. package/lib/engine/engine_disposable.js +136 -0
  32. package/lib/engine/engine_disposable.js.map +1 -0
  33. package/lib/engine/engine_gameobject.d.ts +1 -10
  34. package/lib/engine/engine_gameobject.js +22 -120
  35. package/lib/engine/engine_gameobject.js.map +1 -1
  36. package/lib/engine/engine_gltf_builtin_components.js +7 -69
  37. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  38. package/lib/engine/engine_init.js +16 -1
  39. package/lib/engine/engine_init.js.map +1 -1
  40. package/lib/engine/engine_input.d.ts +1 -1
  41. package/lib/engine/engine_input.js +1 -1
  42. package/lib/engine/engine_input.js.map +1 -1
  43. package/lib/engine/engine_instantiate_resolve.d.ts +42 -0
  44. package/lib/engine/engine_instantiate_resolve.js +372 -0
  45. package/lib/engine/engine_instantiate_resolve.js.map +1 -0
  46. package/lib/engine/engine_license.d.ts +2 -0
  47. package/lib/engine/engine_license.js +14 -6
  48. package/lib/engine/engine_license.js.map +1 -1
  49. package/lib/engine/engine_lifecycle_functions_internal.js +5 -0
  50. package/lib/engine/engine_lifecycle_functions_internal.js.map +1 -1
  51. package/lib/engine/engine_mainloop_utils.js +5 -2
  52. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  53. package/lib/engine/engine_networking.js +3 -1
  54. package/lib/engine/engine_networking.js.map +1 -1
  55. package/lib/engine/engine_networking_blob.js +1 -1
  56. package/lib/engine/engine_networking_blob.js.map +1 -1
  57. package/lib/engine/engine_physics_rapier.d.ts +11 -3
  58. package/lib/engine/engine_physics_rapier.js +88 -25
  59. package/lib/engine/engine_physics_rapier.js.map +1 -1
  60. package/lib/engine/engine_pmrem.js +2 -2
  61. package/lib/engine/engine_pmrem.js.map +1 -1
  62. package/lib/engine/engine_scenedata.d.ts +13 -17
  63. package/lib/engine/engine_scenedata.js +58 -31
  64. package/lib/engine/engine_scenedata.js.map +1 -1
  65. package/lib/engine/engine_serialization_builtin_serializer.d.ts +10 -16
  66. package/lib/engine/engine_serialization_builtin_serializer.js +56 -46
  67. package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
  68. package/lib/engine/engine_serialization_core.d.ts +1 -0
  69. package/lib/engine/engine_serialization_core.js +7 -0
  70. package/lib/engine/engine_serialization_core.js.map +1 -1
  71. package/lib/engine/engine_ssr.d.ts +2 -0
  72. package/lib/engine/engine_ssr.js +20 -0
  73. package/lib/engine/engine_ssr.js.map +1 -1
  74. package/lib/engine/engine_types.d.ts +19 -9
  75. package/lib/engine/engine_types.js +1 -1
  76. package/lib/engine/engine_types.js.map +1 -1
  77. package/lib/engine/engine_util_decorator.js +7 -2
  78. package/lib/engine/engine_util_decorator.js.map +1 -1
  79. package/lib/engine/engine_utils.d.ts +1 -1
  80. package/lib/engine/engine_utils.js +19 -5
  81. package/lib/engine/engine_utils.js.map +1 -1
  82. package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
  83. package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js.map +1 -1
  84. package/lib/engine/webcomponents/jsx.d.ts +51 -0
  85. package/lib/engine/webcomponents/logo-element.js.map +1 -1
  86. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +3 -4
  87. package/lib/engine/webcomponents/needle menu/needle-menu.js +1 -1
  88. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  89. package/lib/engine/webcomponents/needle-button.js.map +1 -1
  90. package/lib/engine/webcomponents/needle-engine.d.ts +10 -4
  91. package/lib/engine/webcomponents/needle-engine.js +1 -1
  92. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  93. package/lib/engine/xr/NeedleXRSession.d.ts +3 -2
  94. package/lib/engine/xr/NeedleXRSession.js +50 -14
  95. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  96. package/lib/engine/xr/events.d.ts +1 -1
  97. package/lib/engine/xr/events.js.map +1 -1
  98. package/lib/engine-components/Animation.js +17 -16
  99. package/lib/engine-components/Animation.js.map +1 -1
  100. package/lib/engine-components/Animator.d.ts +6 -0
  101. package/lib/engine-components/Animator.js +17 -12
  102. package/lib/engine-components/Animator.js.map +1 -1
  103. package/lib/engine-components/AnimatorController.builder.d.ts +113 -0
  104. package/lib/engine-components/AnimatorController.builder.js +195 -0
  105. package/lib/engine-components/AnimatorController.builder.js.map +1 -0
  106. package/lib/engine-components/AnimatorController.d.ts +4 -119
  107. package/lib/engine-components/AnimatorController.js +35 -233
  108. package/lib/engine-components/AnimatorController.js.map +1 -1
  109. package/lib/engine-components/AudioSource.d.ts +19 -3
  110. package/lib/engine-components/AudioSource.js +121 -68
  111. package/lib/engine-components/AudioSource.js.map +1 -1
  112. package/lib/engine-components/Collider.d.ts +18 -9
  113. package/lib/engine-components/Collider.js +61 -14
  114. package/lib/engine-components/Collider.js.map +1 -1
  115. package/lib/engine-components/Component.d.ts +58 -6
  116. package/lib/engine-components/Component.js +77 -0
  117. package/lib/engine-components/Component.js.map +1 -1
  118. package/lib/engine-components/DragControls.d.ts +7 -0
  119. package/lib/engine-components/DragControls.js +19 -7
  120. package/lib/engine-components/DragControls.js.map +1 -1
  121. package/lib/engine-components/EventList.d.ts +31 -9
  122. package/lib/engine-components/EventList.js +37 -76
  123. package/lib/engine-components/EventList.js.map +1 -1
  124. package/lib/engine-components/Joints.d.ts +4 -2
  125. package/lib/engine-components/Joints.js +19 -3
  126. package/lib/engine-components/Joints.js.map +1 -1
  127. package/lib/engine-components/Light.d.ts +6 -8
  128. package/lib/engine-components/Light.js +48 -27
  129. package/lib/engine-components/Light.js.map +1 -1
  130. package/lib/engine-components/Networking.d.ts +1 -1
  131. package/lib/engine-components/Networking.js +1 -1
  132. package/lib/engine-components/OrbitControls.js +16 -11
  133. package/lib/engine-components/OrbitControls.js.map +1 -1
  134. package/lib/engine-components/ReflectionProbe.js +2 -0
  135. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  136. package/lib/engine-components/RigidBody.d.ts +12 -4
  137. package/lib/engine-components/RigidBody.js +18 -4
  138. package/lib/engine-components/RigidBody.js.map +1 -1
  139. package/lib/engine-components/SeeThrough.js +2 -2
  140. package/lib/engine-components/SeeThrough.js.map +1 -1
  141. package/lib/engine-components/api.d.ts +1 -1
  142. package/lib/engine-components/api.js +1 -1
  143. package/lib/engine-components/api.js.map +1 -1
  144. package/lib/engine-components/codegen/components.d.ts +3 -9
  145. package/lib/engine-components/codegen/components.js +3 -9
  146. package/lib/engine-components/codegen/components.js.map +1 -1
  147. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
  148. package/lib/engine-components/postprocessing/VolumeParameter.d.ts +2 -0
  149. package/lib/engine-components/postprocessing/VolumeParameter.js +4 -1
  150. package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -1
  151. package/lib/engine-components/timeline/PlayableDirector.d.ts +16 -6
  152. package/lib/engine-components/timeline/PlayableDirector.js +63 -61
  153. package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
  154. package/lib/engine-components/timeline/SignalAsset.d.ts +3 -1
  155. package/lib/engine-components/timeline/SignalAsset.js +1 -0
  156. package/lib/engine-components/timeline/SignalAsset.js.map +1 -1
  157. package/lib/engine-components/timeline/TimelineBuilder.d.ts +247 -0
  158. package/lib/engine-components/timeline/TimelineBuilder.js +400 -0
  159. package/lib/engine-components/timeline/TimelineBuilder.js.map +1 -0
  160. package/lib/engine-components/timeline/TimelineModels.d.ts +2 -1
  161. package/lib/engine-components/timeline/TimelineModels.js +3 -0
  162. package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
  163. package/lib/engine-components/timeline/TimelineTracks.d.ts +23 -0
  164. package/lib/engine-components/timeline/TimelineTracks.js +71 -13
  165. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  166. package/lib/engine-components/timeline/index.d.ts +2 -1
  167. package/lib/engine-components/timeline/index.js +2 -0
  168. package/lib/engine-components/timeline/index.js.map +1 -1
  169. package/lib/engine-components/ui/Canvas.d.ts +1 -1
  170. package/lib/engine-components/ui/Canvas.js +2 -8
  171. package/lib/engine-components/ui/Canvas.js.map +1 -1
  172. package/lib/engine-components/ui/Text.d.ts +1 -0
  173. package/lib/engine-components/ui/Text.js +10 -7
  174. package/lib/engine-components/ui/Text.js.map +1 -1
  175. package/lib/engine-components/web/CursorFollow.js +21 -12
  176. package/lib/engine-components/web/CursorFollow.js.map +1 -1
  177. package/lib/engine-components/webxr/WebXRImageTracking.js +4 -0
  178. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  179. package/lib/needle-engine.d.ts +2 -0
  180. package/lib/needle-engine.js +2 -0
  181. package/lib/needle-engine.js.map +1 -1
  182. package/package.json +4 -84
  183. package/plugins/common/worker.js +9 -4
  184. package/plugins/dts-generator/dts.codegen.js +255 -50
  185. package/plugins/dts-generator/dts.scan.js +37 -9
  186. package/plugins/dts-generator/dts.writer.js +1 -1
  187. package/plugins/dts-generator/glb.discovery.js +140 -23
  188. package/plugins/dts-generator/glb.extractor.js +48 -8
  189. package/plugins/dts-generator/glb.reader.js +80 -27
  190. package/plugins/dts-generator/index.js +1 -1
  191. package/plugins/types/needle-bindings.d.ts +25 -14
  192. package/plugins/types/userconfig.d.ts +12 -0
  193. package/plugins/vite/asap.js +18 -9
  194. package/plugins/vite/dependencies.js +29 -0
  195. package/plugins/vite/dependency-watcher.d.ts +2 -2
  196. package/plugins/vite/dependency-watcher.js +5 -6
  197. package/plugins/vite/drop.d.ts +2 -2
  198. package/plugins/vite/drop.js +3 -4
  199. package/plugins/vite/dts-generator.d.ts +2 -2
  200. package/plugins/vite/dts-generator.js +43 -9
  201. package/plugins/vite/editor-connection.js +3 -3
  202. package/plugins/vite/index.d.ts +9 -3
  203. package/plugins/vite/index.js +23 -10
  204. package/plugins/vite/local-files-core.js +3 -3
  205. package/plugins/vite/local-files-utils.d.ts +3 -1
  206. package/plugins/vite/local-files-utils.js +29 -5
  207. package/plugins/vite/meta.js +4 -2
  208. package/plugins/vite/poster.d.ts +2 -2
  209. package/plugins/vite/poster.js +3 -5
  210. package/plugins/vite/reload.d.ts +2 -2
  211. package/plugins/vite/reload.js +23 -23
  212. package/plugins/vite/server.js +2 -1
  213. package/src/engine/api.ts +8 -1
  214. package/src/engine/codegen/register_types.ts +2 -10
  215. package/src/engine/debug/debug_spatial_console.ts +10 -7
  216. package/src/engine/engine_addressables.ts +6 -3
  217. package/src/engine/engine_audio.ts +184 -0
  218. package/src/engine/engine_components.ts +1 -1
  219. package/src/engine/engine_context.ts +36 -22
  220. package/src/engine/engine_disposable.ts +213 -0
  221. package/src/engine/engine_gameobject.ts +54 -159
  222. package/src/engine/engine_gltf_builtin_components.ts +7 -76
  223. package/src/engine/engine_init.ts +15 -1
  224. package/src/engine/engine_input.ts +1 -1
  225. package/src/engine/engine_instantiate_resolve.ts +407 -0
  226. package/src/engine/engine_license.ts +12 -10
  227. package/src/engine/engine_lifecycle_functions_internal.ts +7 -0
  228. package/src/engine/engine_mainloop_utils.ts +5 -2
  229. package/src/engine/engine_networking.ts +3 -1
  230. package/src/engine/engine_networking_blob.ts +1 -1
  231. package/src/engine/engine_physics_rapier.ts +82 -27
  232. package/src/engine/engine_pmrem.ts +3 -3
  233. package/src/engine/engine_scenedata.ts +56 -30
  234. package/src/engine/engine_serialization_builtin_serializer.ts +64 -52
  235. package/src/engine/engine_serialization_core.ts +9 -0
  236. package/src/engine/engine_ssr.ts +29 -3
  237. package/src/engine/engine_types.ts +24 -13
  238. package/src/engine/engine_util_decorator.ts +7 -2
  239. package/src/engine/engine_utils.ts +16 -5
  240. package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
  241. package/src/engine/webcomponents/jsx.d.ts +51 -0
  242. package/src/engine/webcomponents/logo-element.ts +1 -0
  243. package/src/engine/webcomponents/needle menu/needle-menu.ts +3 -2
  244. package/src/engine/webcomponents/needle-button.ts +1 -0
  245. package/src/engine/webcomponents/needle-engine.ts +11 -4
  246. package/src/engine/xr/NeedleXRSession.ts +48 -13
  247. package/src/engine/xr/events.ts +1 -1
  248. package/src/engine-components/Animation.ts +19 -16
  249. package/src/engine-components/Animator.ts +18 -11
  250. package/src/engine-components/AnimatorController.builder.ts +261 -0
  251. package/src/engine-components/AnimatorController.ts +23 -292
  252. package/src/engine-components/AudioSource.ts +130 -79
  253. package/src/engine-components/Collider.ts +66 -18
  254. package/src/engine-components/Component.ts +79 -9
  255. package/src/engine-components/DragControls.ts +18 -11
  256. package/src/engine-components/EventList.ts +45 -83
  257. package/src/engine-components/Joints.ts +20 -4
  258. package/src/engine-components/Light.ts +49 -27
  259. package/src/engine-components/Networking.ts +1 -1
  260. package/src/engine-components/OrbitControls.ts +18 -9
  261. package/src/engine-components/ReflectionProbe.ts +2 -0
  262. package/src/engine-components/RigidBody.ts +18 -4
  263. package/src/engine-components/SeeThrough.ts +2 -2
  264. package/src/engine-components/api.ts +1 -1
  265. package/src/engine-components/codegen/components.ts +3 -9
  266. package/src/engine-components/postprocessing/VolumeParameter.ts +4 -1
  267. package/src/engine-components/timeline/PlayableDirector.ts +61 -64
  268. package/src/engine-components/timeline/SignalAsset.ts +4 -1
  269. package/src/engine-components/timeline/TimelineBuilder.ts +565 -0
  270. package/src/engine-components/timeline/TimelineModels.ts +5 -1
  271. package/src/engine-components/timeline/TimelineTracks.ts +74 -13
  272. package/src/engine-components/timeline/index.ts +2 -1
  273. package/src/engine-components/ui/Canvas.ts +2 -8
  274. package/src/engine-components/ui/Text.ts +12 -8
  275. package/src/engine-components/web/CursorFollow.ts +21 -13
  276. package/src/engine-components/webxr/WebXRImageTracking.ts +2 -0
  277. package/src/needle-engine.ts +3 -0
  278. package/dist/needle-engine.bundle-Dq0Ly8fW.umd.cjs +0 -1732
  279. package/dist/needle-engine.bundle-YnpzzOPL.min.js +0 -1732
  280. package/lib/engine-components/AvatarLoader.d.ts +0 -80
  281. package/lib/engine-components/AvatarLoader.js +0 -232
  282. package/lib/engine-components/AvatarLoader.js.map +0 -1
  283. package/lib/engine-components/avatar/AvatarBlink_Simple.d.ts +0 -11
  284. package/lib/engine-components/avatar/AvatarBlink_Simple.js +0 -77
  285. package/lib/engine-components/avatar/AvatarBlink_Simple.js.map +0 -1
  286. package/lib/engine-components/avatar/AvatarEyeLook_Rotation.d.ts +0 -14
  287. package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js +0 -69
  288. package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js.map +0 -1
  289. package/lib/engine-components/avatar/Avatar_Brain_LookAt.d.ts +0 -29
  290. package/lib/engine-components/avatar/Avatar_Brain_LookAt.js +0 -122
  291. package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +0 -1
  292. package/lib/engine-components/avatar/Avatar_MouthShapes.d.ts +0 -15
  293. package/lib/engine-components/avatar/Avatar_MouthShapes.js +0 -80
  294. package/lib/engine-components/avatar/Avatar_MouthShapes.js.map +0 -1
  295. package/lib/engine-components/avatar/Avatar_MustacheShake.d.ts +0 -9
  296. package/lib/engine-components/avatar/Avatar_MustacheShake.js +0 -30
  297. package/lib/engine-components/avatar/Avatar_MustacheShake.js.map +0 -1
  298. package/src/engine-components/AvatarLoader.ts +0 -264
  299. package/src/engine-components/avatar/AvatarBlink_Simple.ts +0 -70
  300. package/src/engine-components/avatar/AvatarEyeLook_Rotation.ts +0 -64
  301. package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +0 -140
  302. package/src/engine-components/avatar/Avatar_MouthShapes.ts +0 -84
  303. package/src/engine-components/avatar/Avatar_MustacheShake.ts +0 -32
@@ -22,7 +22,7 @@ export async function needleAsap(command, config, userSettings) {
22
22
 
23
23
  fixMainTs();
24
24
 
25
- if (command != "build") {
25
+ if (command === "serve") {
26
26
  return null;
27
27
  }
28
28
 
@@ -50,7 +50,7 @@ export async function needleAsap(command, config, userSettings) {
50
50
  const tags = [];
51
51
 
52
52
  try {
53
- generateGltfPreloadLinks(config, html, tags);
53
+ generateGltfPreloadLinks(config, html, tags, viteConfig?.base);
54
54
  }
55
55
  catch (err) {
56
56
  console.error("Error generating gltf preload links", err);
@@ -173,18 +173,21 @@ function fixMainTs() {
173
173
  * @param {import('vite').ResolvedConfig} _config
174
174
  * @param {import('vite').HtmlTagDescriptor[]} tags
175
175
  */
176
- function generateScriptPreloadLinks(_config, tags) {
176
+ function generateScriptPreloadLinks(config, tags) {
177
177
  try {
178
+ const base = config.base || '/';
178
179
  const chunks = preloadScriptPaths;
179
180
  // console.log("ASAP", chunks)
180
181
  if (chunks.length > 0) {
181
182
  for (const chunk of chunks) {
183
+ // Apply base path so preload hrefs resolve correctly under SPA routing
184
+ const href = chunk.startsWith('./') ? base + chunk.slice(2) : chunk;
182
185
  tags.push({
183
186
  tag: 'link',
184
187
  attrs: {
185
188
  rel: "modulepreload",
186
189
  as: "script",
187
- href: chunk,
190
+ href: href,
188
191
  }
189
192
  });
190
193
  }
@@ -203,15 +206,16 @@ const codegenRegex = /\"(?<gltf>.+(.glb|.gltf)(\?.*)?)\"/gm;
203
206
  /**
204
207
  * @param {import('../types').needleConfig} config
205
208
  * @param {string} html
206
- * @param {import('vite').HtmlTagDescriptor[]} tags
209
+ * @param {import('vite').HtmlTagDescriptor[]} tags
210
+ * @param {string} [base]
207
211
  **/
208
- function generateGltfPreloadLinks(config, html, tags) {
212
+ function generateGltfPreloadLinks(config, html, tags, base) {
209
213
 
210
214
  // TODO: try to get the <needle-engine src> element src attribute and preload that
211
215
  const needleEngineMatches = tryParseNeedleEngineSrcAttributeFromHtml(html);
212
216
  if (needleEngineMatches?.length) {
213
217
  for (const item of needleEngineMatches) {
214
- insertPreloadLink(tags, item, "model/gltf+json");
218
+ insertPreloadLink(tags, item, "model/gltf+json", base);
215
219
  }
216
220
  }
217
221
 
@@ -246,7 +250,7 @@ function generateGltfPreloadLinks(config, html, tags) {
246
250
  }
247
251
  }
248
252
  needleLog("needle:asap", `Insert glTF preload link: ${value}`);
249
- insertPreloadLink(tags, value, "model/gltf+json");
253
+ insertPreloadLink(tags, value, "model/gltf+json", base);
250
254
  }
251
255
  }
252
256
  }
@@ -258,9 +262,14 @@ function generateGltfPreloadLinks(config, html, tags) {
258
262
  * @param {import('vite').HtmlTagDescriptor[]} tags
259
263
  * @param {string} href
260
264
  * @param {string} type
265
+ * @param {string} [base]
261
266
  */
262
- function insertPreloadLink(tags, href, type) {
267
+ function insertPreloadLink(tags, href, type, base) {
263
268
  if (!href) return;
269
+ // Apply base path so preload hrefs resolve correctly under SPA routing
270
+ if (base && !href.startsWith('http') && !href.startsWith('/')) {
271
+ href = base + (href.startsWith('./') ? href.slice(2) : href);
272
+ }
264
273
  tags.push({
265
274
  tag: 'link',
266
275
  attrs: {
@@ -61,6 +61,35 @@ export function needleDependencies(command, config, userSettings) {
61
61
  }
62
62
  },
63
63
  },
64
+ // Vite 8's optimizer rebases `new URL(specifier, import.meta.url)` paths
65
+ // inside pre-bundled dependencies (PR #21434), but only handles truly relative
66
+ // paths (./ ../). Bare-specifier paths like `three-mesh-bvh/src/workers/...`
67
+ // are treated as relative to the *source file* that contained the `new URL()`
68
+ // call, producing a wrong URL such as:
69
+ // /node_modules/@needle-tools/engine/.../three-mesh-bvh/src/workers/generateMeshBVH.worker.js
70
+ // This middleware rewrites those broken URLs so the dev server finds the file at
71
+ // its real location in node_modules.
72
+ {
73
+ name: 'needle:worker-url-rewrite',
74
+ configureServer(server) {
75
+ const rewritePackages = ['three-mesh-bvh'];
76
+ server.middlewares.use((req, _res, next) => {
77
+ if (req.url) {
78
+ for (const pkg of rewritePackages) {
79
+ const marker = `/${pkg}/`;
80
+ if (req.url.includes(marker) && !req.url.startsWith(`/node_modules/${pkg}/`)) {
81
+ const idx = req.url.indexOf(marker);
82
+ const rewritten = '/node_modules' + req.url.slice(idx);
83
+ needleLog('needle-dependencies', `Rewriting worker URL → ${rewritten}`);
84
+ req.url = rewritten;
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ next();
90
+ });
91
+ },
92
+ },
64
93
  ]
65
94
  }
66
95
 
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @param {"build" | "serve"} command
2
+ * @param {"build" | "serve" | undefined} _command
3
3
  * @param {unknown} _config
4
4
  * @param {import('../types').userSettings} userSettings
5
5
  * @returns {import('vite').Plugin | null}
6
6
  */
7
- export function needleDependencyWatcher(command: "build" | "serve", _config: unknown, userSettings: import("../types").userSettings): import("vite").Plugin | null;
7
+ export function needleDependencyWatcher(_command: "build" | "serve" | undefined, _config: unknown, userSettings: import("../types").userSettings): import("vite").Plugin | null;
8
8
  export type PackageJson = {
9
9
  dependencies?: Record<string, string>;
10
10
  devDependencies?: Record<string, string>;
@@ -12,14 +12,12 @@ function log(...msg) {
12
12
  }
13
13
 
14
14
  /**
15
- * @param {"build" | "serve"} command
15
+ * @param {"build" | "serve" | undefined} _command
16
16
  * @param {unknown} _config
17
17
  * @param {import('../types').userSettings} userSettings
18
18
  * @returns {import('vite').Plugin | null}
19
19
  */
20
- export function needleDependencyWatcher(command, _config, userSettings) {
21
- if (command === "build") return null;
22
-
20
+ export function needleDependencyWatcher(_command, _config, userSettings) {
23
21
  if (userSettings?.noDependencyWatcher === true) return null;
24
22
 
25
23
  const dir = process.cwd();
@@ -28,6 +26,7 @@ export function needleDependencyWatcher(command, _config, userSettings) {
28
26
 
29
27
  return /** @type {import('vite').Plugin} */ ({
30
28
  name: 'needle-dependency-watcher',
29
+ apply: 'serve',
31
30
  /** @param {import('vite').ViteDevServer} server */
32
31
  configureServer(server) {
33
32
  manageClients(server);
@@ -99,7 +98,7 @@ function watchPackageJson(server, projectDir, packageJsonPath, cachePath) {
99
98
 
100
99
  setTimeout(() => {
101
100
  requireInstall = testIfInstallIsRequired(projectDir, packageJson);
102
- }, 1000);
101
+ }, 1000).unref();
103
102
 
104
103
  setInterval(() => {
105
104
  if (!packageJson || lastEditTime === undefined) return;
@@ -150,7 +149,7 @@ function watchPackageJson(server, projectDir, packageJsonPath, cachePath) {
150
149
  restart(server, projectDir, cachePath);
151
150
  }
152
151
  }
153
- }, 2000);
152
+ }, 2000).unref();
154
153
  }
155
154
 
156
155
  /** @param {string} projectDir @param {PackageJson | undefined} packageJson @returns {boolean} */
@@ -1,7 +1,7 @@
1
1
  /** Experimental, allow dropping files from Unity into the running scene.
2
- * @param {"build" | "serve"} command
2
+ * @param {"build" | "serve" | undefined} _command
3
3
  * @param {import('../types/needleConfig').needleMeta | null | undefined} config
4
4
  * @param {import('../types/userconfig.js').userSettings} userSettings
5
5
  * @returns {import('vite').Plugin | null | undefined}
6
6
  */
7
- export function needleDrop(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types/userconfig.js").userSettings): import("vite").Plugin | null | undefined;
7
+ export function needleDrop(_command: "build" | "serve" | undefined, config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types/userconfig.js").userSettings): import("vite").Plugin | null | undefined;
@@ -7,18 +7,17 @@ const __filename = fileURLToPath(import.meta.url);
7
7
  const __dirname = path.dirname(__filename);
8
8
 
9
9
  /** Experimental, allow dropping files from Unity into the running scene.
10
- * @param {"build" | "serve"} command
10
+ * @param {"build" | "serve" | undefined} _command
11
11
  * @param {import('../types/needleConfig').needleMeta | null | undefined} config
12
12
  * @param {import('../types/userconfig.js').userSettings} userSettings
13
13
  * @returns {import('vite').Plugin | null | undefined}
14
14
  */
15
- export function needleDrop(command, config, userSettings) {
16
- if (command === "build") return;
17
-
15
+ export function needleDrop(_command, config, userSettings) {
18
16
  if(userSettings.useDrop !== true) return null;
19
17
 
20
18
  return {
21
19
  name: "needle:drop",
20
+ apply: 'serve',
22
21
  config(/** @type {{ server?: { hmr?: { port?: number } } }} */ viteConfig) {
23
22
  if(userSettings)
24
23
  if (!viteConfig.server) viteConfig.server = {};
@@ -2,6 +2,6 @@
2
2
  * @param {"build" | "serve"} _command Vite command (unused — runs in both modes)
3
3
  * @param {import('../types/needleConfig').needleMeta | null | undefined} _config
4
4
  * @param {import('../types').userSettings} [_userSettings]
5
- * @returns {import('vite').Plugin}
5
+ * @returns {import('vite').Plugin | null}
6
6
  */
7
- export function needleDtsGenerator(_command: "build" | "serve", _config: import("../types/needleConfig").needleMeta | null | undefined, _userSettings?: import("../types").userSettings): import("vite").Plugin;
7
+ export function needleDtsGenerator(_command: "build" | "serve", _config: import("../types/needleConfig").needleMeta | null | undefined, _userSettings?: import("../types").userSettings): import("vite").Plugin | null;
@@ -16,12 +16,24 @@
16
16
  * needleDtsGenerator(command, needleConfig, userSettings)
17
17
  */
18
18
 
19
- import { join, resolve } from 'path';
20
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
19
+ import { join, resolve, dirname } from 'path';
20
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, realpathSync } from 'fs';
21
21
  import { tryLoadProjectConfig } from './config.js';
22
22
  import { generateBindingsDts } from '../dts-generator/index.js';
23
23
  import { needleLog } from './logging.js';
24
24
 
25
+ // Two dirs up from plugins/vite/ → package root.
26
+ // Use fileURLToPath so %7E and other URL-encoded characters in the path are decoded correctly.
27
+ // realpathSync follows symlinks so the path is stable even in npm link / monorepo setups.
28
+ import { fileURLToPath } from 'url';
29
+ let _packageRoot = /** @type {string | null} */ (null);
30
+ try {
31
+ _packageRoot = realpathSync(join(dirname(fileURLToPath(import.meta.url)), '..', '..'));
32
+ } catch (_e) {
33
+ // If we can't resolve the package root (e.g. unusual install layout), the plugin
34
+ // will silently skip generation rather than crashing the dev server.
35
+ }
36
+
25
37
  /**
26
38
  * Ensure `.vscode/settings.json` references the generated `needle-html-data.json`
27
39
  * so VS Code provides `data-bind-needle` completions in HTML files automatically.
@@ -60,9 +72,14 @@ function ensureVscodeHtmlCustomData(projectRoot, htmlDataPath) {
60
72
  * @param {"build" | "serve"} _command Vite command (unused — runs in both modes)
61
73
  * @param {import('../types/needleConfig').needleMeta | null | undefined} _config
62
74
  * @param {import('../types').userSettings} [_userSettings]
63
- * @returns {import('vite').Plugin}
75
+ * @returns {import('vite').Plugin | null}
64
76
  */
65
77
  export function needleDtsGenerator(_command, _config, _userSettings) {
78
+
79
+ if(_userSettings?.dts?.enabled === false) {
80
+ return null;
81
+ }
82
+
66
83
  let projectRoot = process.cwd();
67
84
 
68
85
  function resolveCodegenDir() {
@@ -73,7 +90,11 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
73
90
  }
74
91
 
75
92
  function resolveOutputPath() {
76
- return join(resolveCodegenDir(), "needle-bindings.d.ts");
93
+ // Write to a .needle dotfolder at the package root.
94
+ // Not in the `files` allowlist → never npm-published.
95
+ // ../../.needle/ from plugins/types/ resolves correctly for both
96
+ // symlinked (js/package~/) and published (node_modules/@needle-tools/engine/) layouts.
97
+ return join(/** @type {string} */ (_packageRoot), ".needle", "generated", "needle-bindings.gen.d.ts");
77
98
  }
78
99
 
79
100
  function resolveAssetsDir() {
@@ -86,14 +107,24 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
86
107
  /** @type {import('vite').ViteDevServer | undefined} */
87
108
  let devServer;
88
109
 
89
- async function run() {
110
+ /** @type {Promise<void> | null} */
111
+ let _runInFlight = null;
112
+
113
+ function run() {
114
+ if (_runInFlight) return _runInFlight;
115
+ _runInFlight = _doRun().finally(() => { _runInFlight = null; });
116
+ return _runInFlight;
117
+ }
118
+
119
+ async function _doRun() {
90
120
  try {
121
+ if (!_packageRoot) return;
91
122
  const assetsDir = resolveAssetsDir();
92
123
  const outputPath = resolveOutputPath();
93
124
  const codegenDir = resolveCodegenDir();
94
125
  const count = await generateBindingsDts({ assetsDir, outputPath, projectRoot, codegenDir });
95
- // Always register HTML custom data — the file is written on every run
96
- const htmlDataPath = join(codegenDir, "needle-html-data.json");
126
+ // HTML custom data sits next to the generated dts in .needle/generated/
127
+ const htmlDataPath = join(/** @type {string} */ (_packageRoot), ".needle", "generated", "needle-html-data.json");
97
128
  ensureVscodeHtmlCustomData(projectRoot, htmlDataPath);
98
129
  if (count !== false) {
99
130
  needleLog("needle:dts-generator", `${count} binding(s) → ${outputPath.replace(process.cwd(), ".")}`);
@@ -102,7 +133,7 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
102
133
  hot.send({ type: "full-reload", path: "*" });
103
134
  }
104
135
  } else {
105
- needleLog("needle:dts-generator", `up-to-date`);
136
+ needleLog("needle:dts-generator", `up-to-date → ${outputPath.replace(process.cwd(), ".")}`);
106
137
  }
107
138
  } catch (err) {
108
139
  needleLog("needle:dts-generator", "Failed: " + (/** @type {any} */ (err)?.message ?? err));
@@ -118,7 +149,10 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
118
149
  },
119
150
 
120
151
  buildStart() {
121
- return run();
152
+ // In serve mode, the configureServer post-hook runs instead.
153
+ // Only run here for actual builds (no devServer).
154
+ if (!devServer) return run();
155
+ return undefined;
122
156
  },
123
157
 
124
158
  /** @param {import('vite').ViteDevServer} server */
@@ -27,7 +27,7 @@ export async function editorConnection(command, config, userSettings, pluginsArr
27
27
  if (typeof config.generator === "string" && !config.generator.includes("Unity")) return;
28
28
 
29
29
  if (!config) {
30
- setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync can not be installed automatically to vite: missing config", "warn"), 1000);
30
+ setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync can not be installed automatically to vite: missing config", "warn"), 1000).unref();
31
31
  return createPlugin(false);
32
32
  }
33
33
 
@@ -42,14 +42,14 @@ export async function editorConnection(command, config, userSettings, pluginsArr
42
42
  // }
43
43
  // }
44
44
  if (needleEditorSettings && needleEditorSettings.enabled === false) {
45
- setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync is not enabled. Add a 'Needle Editor Sync' component to your scene to enable", "warn"), 1000);
45
+ setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync is not enabled. Add a 'Needle Editor Sync' component to your scene to enable", "warn"), 1000).unref();
46
46
  return createPlugin(false);
47
47
  }
48
48
 
49
49
  // Check if the editor package is installed
50
50
  let path = root + `/node_modules/${editorSyncPackageName}/plugins/index.js`;
51
51
  if (existsSync(path) === false) {
52
- setTimeout(() => needleLog("needle-editor-sync", `${editorSyncPackageName} is not installed: Add the "Needle Editor Sync" component to your scene if you want to send changes directly from the Unity Editor to web app`, "warn"), 1000);
52
+ setTimeout(() => needleLog("needle-editor-sync", `${editorSyncPackageName} is not installed: Add the "Needle Editor Sync" component to your scene if you want to send changes directly from the Unity Editor to web app`, "warn"), 1000).unref();
53
53
  return createPlugin(false);
54
54
  }
55
55
 
@@ -19,12 +19,18 @@
19
19
  * ],
20
20
  * }
21
21
  * ```
22
- * @param {"build" | "serve"} command
23
- * @param {import('../types/needleConfig').needleMeta | null | undefined} config
22
+ * When used without arguments (e.g. in a SvelteKit `defineConfig({})` plain object),
23
+ * the command is resolved automatically from Vite's `configResolved` hook.
24
+ * ```js
25
+ * // SvelteKit — no command needed:
26
+ * export default defineConfig({ plugins: [sveltekit(), needlePlugins()] });
27
+ * ```
28
+ * @param {"build" | "serve" | undefined} [command]
29
+ * @param {import('../types/needleConfig').needleMeta | null | undefined} [config]
24
30
  * @param {import('../types/index.js').userSettings} [userSettings]
25
31
  * @returns {Promise<import('vite').Plugin[]>}
26
32
  */
27
- export function needlePlugins(command: "build" | "serve", config?: import("../types/needleConfig").needleMeta | null | undefined, userSettings?: import("../types/index.js").userSettings): Promise<import("vite").Plugin[]>;
33
+ export function needlePlugins(command?: "build" | "serve" | undefined, config?: import("../types/needleConfig").needleMeta | null | undefined, userSettings?: import("../types/index.js").userSettings): Promise<import("vite").Plugin[]>;
28
34
  export { needleAI } from "./ai.js";
29
35
  export { needleDtsGenerator } from "./dts-generator.js";
30
36
  export { needleAsap } from "./asap.js";
@@ -116,12 +116,18 @@ const defaultUserSettings = {
116
116
  * ],
117
117
  * }
118
118
  * ```
119
- * @param {"build" | "serve"} command
120
- * @param {import('../types/needleConfig').needleMeta | null | undefined} config
119
+ * When used without arguments (e.g. in a SvelteKit `defineConfig({})` plain object),
120
+ * the command is resolved automatically from Vite's `configResolved` hook.
121
+ * ```js
122
+ * // SvelteKit — no command needed:
123
+ * export default defineConfig({ plugins: [sveltekit(), needlePlugins()] });
124
+ * ```
125
+ * @param {"build" | "serve" | undefined} [command]
126
+ * @param {import('../types/needleConfig').needleMeta | null | undefined} [config]
121
127
  * @param {import('../types/index.js').userSettings} [userSettings]
122
128
  * @returns {Promise<import('vite').Plugin[]>}
123
129
  */
124
- export async function needlePlugins(command, config = undefined, userSettings = {}) {
130
+ export async function needlePlugins(command = undefined, config = undefined, userSettings = {}) {
125
131
 
126
132
  if (!config) config = {}
127
133
 
@@ -168,14 +174,21 @@ export async function needlePlugins(command, config = undefined, userSettings =
168
174
  array.push(await editorConnection(command, config, userSettings, array));
169
175
  array.push(needleDependencyWatcher(command, config, userSettings));
170
176
 
171
- // Ensure the process exits on SIGINT (Ctrl+C) since plugin timers/sockets can keep the event loop alive
172
- if (command === "serve") {
177
+ // Ensure the process exits on SIGINT (Ctrl+C) since plugin timers/sockets can keep the event loop alive.
178
+ // If command is unknown at call time (e.g. SvelteKit plain defineConfig), defer to configResolved.
179
+ const registerSigint = () => {
173
180
  process.on('SIGINT', () => {
174
- // Wait a moment to allow plugins to clean up if needed, then exit
175
- setTimeout(() => {
176
- console.debug('\nGoodbye!');
177
- process.exit();
178
- }, 1000);
181
+ setTimeout(() => { console.debug('\nGoodbye!'); process.exit(); }, 1000);
182
+ });
183
+ };
184
+ if (command === "serve") {
185
+ registerSigint();
186
+ } else if (command === undefined) {
187
+ array.push({
188
+ name: "needle:sigint",
189
+ configResolved(config) {
190
+ if (config.command === "serve") registerSigint();
191
+ }
179
192
  });
180
193
  }
181
194
 
@@ -291,7 +291,7 @@ export function needleMakeFilesLocal(command, _config, userSettings) {
291
291
  failedDownloads,
292
292
  localizationStats,
293
293
  }, activeHandlers);
294
- src = fixRelativeNewURL(src);
294
+ src = fixRelativeNewURL(src, viteConfig?.base);
295
295
  }
296
296
  catch (err) {
297
297
  needleLog("needle:local-files", "Error in transform: " + getErrMessage(err), "error");
@@ -303,7 +303,7 @@ export function needleMakeFilesLocal(command, _config, userSettings) {
303
303
  },
304
304
  renderChunk(code, chunk) {
305
305
  if (!chunk.fileName?.endsWith(".js")) return null;
306
- const fixed = fixRelativeNewURL(code);
306
+ const fixed = fixRelativeNewURL(code, viteConfig?.base);
307
307
  if (fixed === code) return null;
308
308
  return {
309
309
  code: fixed,
@@ -314,7 +314,7 @@ export function needleMakeFilesLocal(command, _config, userSettings) {
314
314
  for (const output of Object.values(bundle)) {
315
315
  if (output.type !== "chunk") continue;
316
316
  if (!output.fileName?.endsWith(".js")) continue;
317
- const fixed = fixRelativeNewURL(output.code);
317
+ const fixed = fixRelativeNewURL(output.code, viteConfig?.base);
318
318
  if (fixed !== output.code) output.code = fixed;
319
319
  }
320
320
  },
@@ -24,9 +24,11 @@ export function normalizeWebPath(path: string): string;
24
24
  export function ensureTrailingSlash(path: string): string;
25
25
  /**
26
26
  * @param {string} src
27
+ * @param {string} [base] - Vite base path (e.g. "/" or "/app/"). When provided,
28
+ * ext/ paths are made absolute so they resolve correctly under SPA routing.
27
29
  * @returns {string}
28
30
  */
29
- export function fixRelativeNewURL(src: string): string;
31
+ export function fixRelativeNewURL(src: string, base?: string): string;
30
32
  /**
31
33
  * @param {string} src
32
34
  * @returns {string}
@@ -113,25 +113,49 @@ export function ensureTrailingSlash(path) {
113
113
 
114
114
  /**
115
115
  * @param {string} src
116
+ * @param {string} [base] - Vite base path (e.g. "/" or "/app/"). When provided,
117
+ * ext/ paths are made absolute so they resolve correctly under SPA routing.
116
118
  * @returns {string}
117
119
  */
118
- export function fixRelativeNewURL(src) {
120
+ export function fixRelativeNewURL(src, base) {
121
+ /** @param {string} path */
122
+ function makeAbsolute(path) {
123
+ // Strip any leading ./ ../ or / prefix to get the clean ext/... path
124
+ const clean = path.replace(/^(?:\.\.?\/)+/, '').replace(/^\//, '');
125
+ if (base) return base.replace(/\/+$/, '') + '/' + clean;
126
+ return clean;
127
+ }
128
+
119
129
  src = src.replace(
120
130
  /(?<==\s*)(["'])((?:(?:\.{1,2}\/)|\/)?ext\/[^"']*\/)\1/g,
121
131
  (/** @type {string} */ _match, /** @type {string} */ quote, /** @type {string} */ path) => {
122
- const runtimePath = path.startsWith("/ext/") ? path.substring(1) : path;
123
- return `new URL(${quote}${runtimePath}${quote}, self.location?.href || ${quote}${quote}).href`;
132
+ const resolved = makeAbsolute(path);
133
+ return `new URL(${quote}${resolved}${quote}, self.location?.href || ${quote}${quote}).href`;
124
134
  }
125
135
  );
126
136
 
127
137
  src = src.replace(
128
138
  /new\s+URL\s*\(\s*(["'`])((?:(?:\.{1,2}\/)|\/)?ext\/[^"'`]+)\1\s*\)/g,
129
139
  (/** @type {string} */ _match, /** @type {string} */ quote, /** @type {string} */ path) => {
130
- const runtimePath = path.startsWith("/ext/") ? path.substring(1) : path;
131
- return `new URL(${quote}${runtimePath}${quote}, self.location?.href)`;
140
+ const resolved = makeAbsolute(path);
141
+ return `new URL(${quote}${resolved}${quote}, self.location?.href)`;
132
142
  }
133
143
  );
134
144
 
145
+ // Make remaining ext/ string literals absolute (e.g. font paths passed as
146
+ // function arguments like addVariant("normal","normal","ext/fonts/...")).
147
+ // The regexes above already consumed paths inside new URL() calls and
148
+ // assignment-based patterns, so this only catches leftover bare strings.
149
+ if (base) {
150
+ src = src.replace(
151
+ /(["'`])((?:\.{1,2}\/)?ext\/[^"'`]+)\1/g,
152
+ (/** @type {string} */ _match, /** @type {string} */ quote, /** @type {string} */ path) => {
153
+ const resolved = makeAbsolute(path);
154
+ return `${quote}${resolved}${quote}`;
155
+ }
156
+ );
157
+ }
158
+
135
159
  return src;
136
160
  }
137
161
 
@@ -13,8 +13,7 @@ import { needleGreenBold, needleLog } from './logging.js';
13
13
  */
14
14
  export function needleMeta(command, config, userSettings) {
15
15
 
16
- // we can check if this is a build
17
- const isBuild = command === 'build';
16
+ let isBuild = command === 'build';
18
17
 
19
18
  async function updateConfig() {
20
19
  config = await loadConfig();
@@ -25,6 +24,9 @@ export function needleMeta(command, config, userSettings) {
25
24
  return {
26
25
  // replace meta tags
27
26
  name: 'needle:meta',
27
+ configResolved(resolvedConfig) {
28
+ isBuild = resolvedConfig.command === 'build';
29
+ },
28
30
  transformIndexHtml: {
29
31
  order: 'pre',
30
32
  handler(/** @type {string} */ html, /** @type {unknown} */ _ctx) {
@@ -1,8 +1,8 @@
1
1
  export function getPosterPath(): string;
2
2
  /**
3
- * @param {"build" | "serve"} command
3
+ * @param {"build" | "serve" | undefined} _command
4
4
  * @param {import('../types/needleConfig').needleMeta | null | undefined} config
5
5
  * @param {import('../types').userSettings} userSettings
6
6
  * @returns {import('vite').Plugin | undefined}
7
7
  */
8
- export function needlePoster(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
8
+ export function needlePoster(_command: "build" | "serve" | undefined, config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
@@ -10,19 +10,17 @@ export function getPosterPath() {
10
10
  }
11
11
 
12
12
  /**
13
- * @param {"build" | "serve"} command
13
+ * @param {"build" | "serve" | undefined} _command
14
14
  * @param {import('../types/needleConfig').needleMeta | null | undefined} config
15
15
  * @param {import('../types').userSettings} userSettings
16
16
  * @returns {import('vite').Plugin | undefined}
17
17
  */
18
- export function needlePoster(command, config, userSettings) {
19
- // only relevant for local development
20
- if (command === 'build') return [];
21
-
18
+ export function needlePoster(_command, config, userSettings) {
22
19
  if (userSettings.noPoster) return;
23
20
 
24
21
  return {
25
22
  name: 'needle:poster',
23
+ apply: 'serve',
26
24
  configureServer(server) {
27
25
  const hot = server.hot ?? server.ws;
28
26
  hot.on('needle:screenshot', async (data, client) => {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @param {"build" | "serve"} command
2
+ * @param {"build" | "serve" | undefined} _command
3
3
  * @param {import('../types/needleConfig').needleMeta | null} config
4
4
  * @param {import('../types').userSettings} userSettings
5
5
  * @returns {import('vite').Plugin | undefined}
6
6
  */
7
- export function needleReload(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
7
+ export function needleReload(_command: "build" | "serve" | undefined, config: import("../types/needleConfig").needleMeta | null, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;