@mantiq/vite 0.5.3 → 0.5.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantiq/vite",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Vite dev server & manifest integration",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/Vite.ts CHANGED
@@ -474,6 +474,11 @@ export class Vite {
474
474
  getConfig(): Readonly<ViteConfig> {
475
475
  return this.config
476
476
  }
477
+
478
+ /** Returns the application base path. */
479
+ getBasePath(): string {
480
+ return this.basePath
481
+ }
477
482
  }
478
483
 
479
484
  /** Escape HTML special characters to prevent XSS. */
@@ -1,4 +1,4 @@
1
- import { ServiceProvider, ConfigRepository } from '@mantiq/core'
1
+ import { ServiceProvider, ConfigRepository, HttpKernel } from '@mantiq/core'
2
2
  import { Vite } from './Vite.ts'
3
3
  import { ServeStaticFiles } from './middleware/ServeStaticFiles.ts'
4
4
 
@@ -44,5 +44,14 @@ export class ViteServiceProvider extends ServiceProvider {
44
44
  }
45
45
 
46
46
  await vite.initialize()
47
+
48
+ // Register 'static' middleware and prepend to global stack for asset serving
49
+ try {
50
+ const kernel = this.app.make(HttpKernel)
51
+ kernel.registerMiddleware('static', ServeStaticFiles)
52
+ kernel.prependGlobalMiddleware('static')
53
+ } catch {
54
+ // HttpKernel may not be available in CLI context
55
+ }
47
56
  }
48
57
  }
@@ -23,7 +23,14 @@ export class ServeStaticFiles implements Middleware {
23
23
 
24
24
  private getPublicDir(): string {
25
25
  if (this.publicDir) return this.publicDir
26
- if (this.vite) return this.vite.getConfig().publicDir
26
+ if (this.vite) {
27
+ const publicDir = this.vite.getConfig().publicDir
28
+ const basePath = this.vite.getBasePath()
29
+ if (basePath && !publicDir.startsWith('/')) {
30
+ return `${basePath}/${publicDir}`
31
+ }
32
+ return publicDir
33
+ }
27
34
  return 'public'
28
35
  }
29
36