@adonisjs/vite 5.0.1-next.2 → 5.1.0-next.0
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/build/{chunk-AHFYQLFC.js → chunk-47LUVDLW.js} +110 -19
- package/build/chunk-AF6PV64J.js +56 -0
- package/build/index.js +1 -1
- package/build/providers/vite_provider.d.ts +66 -6
- package/build/providers/vite_provider.js +65 -9
- package/build/src/client/config.d.ts +17 -2
- package/build/src/define_config.d.ts +9 -1
- package/build/src/plugins/edge.d.ts +14 -2
- package/build/src/utils.d.ts +23 -3
- package/build/src/vite.d.ts +109 -15
- package/build/src/vite_middleware.d.ts +21 -1
- package/build/src/vite_middleware.js +1 -1
- package/package.json +7 -7
- package/build/chunk-FDN2SRQF.js +0 -25
|
@@ -16,8 +16,22 @@ var Vite = class {
|
|
|
16
16
|
#manifestCache;
|
|
17
17
|
#options;
|
|
18
18
|
#devServer;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Indicates whether the Vite manifest file exists on disk
|
|
21
|
+
*/
|
|
20
22
|
hasManifestFile;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new Vite instance for managing asset compilation and serving
|
|
25
|
+
*
|
|
26
|
+
* @param options - Configuration options for Vite integration
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const vite = new Vite({
|
|
30
|
+
* buildDirectory: 'build',
|
|
31
|
+
* assetsUrl: '/assets',
|
|
32
|
+
* manifestFile: 'build/manifest.json'
|
|
33
|
+
* })
|
|
34
|
+
*/
|
|
21
35
|
constructor(options) {
|
|
22
36
|
this.#options = options;
|
|
23
37
|
this.#options.assetsUrl = (this.#options.assetsUrl || "/").replace(/\/$/, "");
|
|
@@ -242,7 +256,24 @@ var Vite = class {
|
|
|
242
256
|
return preloadsElements.concat(tags.map(({ tag }) => tag));
|
|
243
257
|
}
|
|
244
258
|
/**
|
|
245
|
-
* Generate tags for the entry points
|
|
259
|
+
* Generate HTML tags (script and link) for the specified entry points
|
|
260
|
+
*
|
|
261
|
+
* In development mode, includes HMR script and dynamically discovers CSS files.
|
|
262
|
+
* In production mode, uses the manifest file to generate optimized tags with preloading.
|
|
263
|
+
*
|
|
264
|
+
* @param entryPoints - Single entry point or array of entry points to generate tags for
|
|
265
|
+
* @param attributes - Additional HTML attributes to apply to the generated tags
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* // Generate tags for a single entry point
|
|
269
|
+
* const tags = await vite.generateEntryPointsTags('app.js')
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* // Generate tags for multiple entry points with custom attributes
|
|
273
|
+
* const tags = await vite.generateEntryPointsTags(
|
|
274
|
+
* ['app.js', 'admin.js'],
|
|
275
|
+
* { defer: true }
|
|
276
|
+
* )
|
|
246
277
|
*/
|
|
247
278
|
async generateEntryPointsTags(entryPoints, attributes) {
|
|
248
279
|
entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints];
|
|
@@ -252,13 +283,27 @@ var Vite = class {
|
|
|
252
283
|
return this.#generateEntryPointsTagsWithManifest(entryPoints, attributes);
|
|
253
284
|
}
|
|
254
285
|
/**
|
|
255
|
-
* Returns the
|
|
286
|
+
* Returns the base URL for serving static assets
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* const url = vite.assetsUrl()
|
|
290
|
+
* // Returns: '/assets' or '/build' depending on configuration
|
|
256
291
|
*/
|
|
257
292
|
assetsUrl() {
|
|
258
293
|
return this.#options.assetsUrl;
|
|
259
294
|
}
|
|
260
295
|
/**
|
|
261
|
-
* Returns path to a
|
|
296
|
+
* Returns the full URL path to a specific asset file
|
|
297
|
+
*
|
|
298
|
+
* In development mode, returns the asset path with leading slash.
|
|
299
|
+
* In production mode, uses the manifest file to return the versioned/hashed asset URL.
|
|
300
|
+
*
|
|
301
|
+
* @param asset - The relative path to the asset file
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* const path = vite.assetPath('images/logo.png')
|
|
305
|
+
* // Dev: '/images/logo.png'
|
|
306
|
+
* // Prod: '/assets/images/logo-abc123.png'
|
|
262
307
|
*/
|
|
263
308
|
assetPath(asset) {
|
|
264
309
|
if (!this.hasManifestFile) {
|
|
@@ -268,9 +313,16 @@ var Vite = class {
|
|
|
268
313
|
return this.#generateAssetUrl(chunk.file);
|
|
269
314
|
}
|
|
270
315
|
/**
|
|
271
|
-
* Returns the manifest file contents
|
|
316
|
+
* Returns the parsed Vite manifest file contents
|
|
272
317
|
*
|
|
273
|
-
*
|
|
318
|
+
* The manifest file contains information about compiled assets including
|
|
319
|
+
* file paths, integrity hashes, and import dependencies.
|
|
320
|
+
*
|
|
321
|
+
* @throws Will throw an exception when running in development mode
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* const manifest = vite.manifest()
|
|
325
|
+
* console.log(manifest['app.js'].file) // 'assets/app-abc123.js'
|
|
274
326
|
*/
|
|
275
327
|
manifest() {
|
|
276
328
|
if (!this.hasManifestFile) {
|
|
@@ -282,45 +334,84 @@ var Vite = class {
|
|
|
282
334
|
return this.#manifestCache;
|
|
283
335
|
}
|
|
284
336
|
/**
|
|
285
|
-
*
|
|
337
|
+
* Creates and initializes the Vite development server
|
|
338
|
+
*
|
|
339
|
+
* Lazy loads Vite APIs to avoid importing them in production.
|
|
340
|
+
* The server runs in middleware mode and is configured for custom app integration.
|
|
341
|
+
*
|
|
342
|
+
* @param options - Additional Vite configuration options to merge with defaults
|
|
286
343
|
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
344
|
+
* @example
|
|
345
|
+
* await vite.createDevServer({
|
|
346
|
+
* root: './src',
|
|
347
|
+
* server: { port: 3000 }
|
|
348
|
+
* })
|
|
289
349
|
*/
|
|
290
350
|
async createDevServer(options) {
|
|
291
351
|
const { createServer } = await import("vite");
|
|
292
|
-
this.#
|
|
352
|
+
this.#devServer = await createServer({
|
|
293
353
|
server: { middlewareMode: true },
|
|
294
354
|
appType: "custom",
|
|
295
355
|
...options
|
|
296
356
|
});
|
|
297
|
-
this.#devServer = await this.#createServerPromise;
|
|
298
357
|
}
|
|
299
358
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* it
|
|
359
|
+
* Creates a server-side module runner for executing modules in Node.js context
|
|
360
|
+
*
|
|
361
|
+
* Only available in development mode as it requires the Vite dev server.
|
|
362
|
+
* Useful for server-side rendering and module transformation.
|
|
363
|
+
*
|
|
364
|
+
* @param options - Configuration options for the module runner
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* const runner = await vite.createModuleRunner({
|
|
368
|
+
* hmr: { port: 24678 }
|
|
369
|
+
* })
|
|
370
|
+
* const mod = await runner.import('./app.js')
|
|
303
371
|
*/
|
|
304
372
|
async createModuleRunner(options = {}) {
|
|
305
373
|
const { createServerModuleRunner } = await import("vite");
|
|
306
374
|
return createServerModuleRunner(this.#devServer.environments.ssr, options);
|
|
307
375
|
}
|
|
308
376
|
/**
|
|
309
|
-
*
|
|
377
|
+
* Gracefully stops the Vite development server
|
|
378
|
+
*
|
|
379
|
+
* Waits for the server creation promise to complete before closing.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* await vite.stopDevServer()
|
|
310
383
|
*/
|
|
311
384
|
async stopDevServer() {
|
|
312
|
-
await this.#createServerPromise;
|
|
313
385
|
await this.#devServer?.close();
|
|
314
386
|
}
|
|
315
387
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
388
|
+
* Returns the Vite development server instance
|
|
389
|
+
*
|
|
390
|
+
* Only available in development mode after calling createDevServer().
|
|
391
|
+
* Returns undefined in production or if the server hasn't been created yet.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* const server = vite.getDevServer()
|
|
395
|
+
* if (server) {
|
|
396
|
+
* console.log('Dev server is running on', server.config.server.port)
|
|
397
|
+
* }
|
|
318
398
|
*/
|
|
319
399
|
getDevServer() {
|
|
320
400
|
return this.#devServer;
|
|
321
401
|
}
|
|
322
402
|
/**
|
|
323
|
-
*
|
|
403
|
+
* Generates the React Hot Module Replacement (HMR) script for development
|
|
404
|
+
*
|
|
405
|
+
* Only returns a script element in development mode. In production mode,
|
|
406
|
+
* returns null since HMR is not needed.
|
|
407
|
+
*
|
|
408
|
+
* @param attributes - Additional HTML attributes to apply to the script tag
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* const hmrScript = vite.getReactHmrScript({ async: true })
|
|
412
|
+
* if (hmrScript) {
|
|
413
|
+
* console.log(hmrScript.toString()) // <script type="module" async>...</script>
|
|
414
|
+
* }
|
|
324
415
|
*/
|
|
325
416
|
getReactHmrScript(attributes) {
|
|
326
417
|
if (this.hasManifestFile) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/vite_middleware.ts
|
|
2
|
+
var ViteMiddleware = class {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new ViteMiddleware instance
|
|
5
|
+
*
|
|
6
|
+
* @param vite - The Vite instance containing the dev server
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const middleware = new ViteMiddleware(viteInstance)
|
|
10
|
+
*/
|
|
11
|
+
constructor(vite) {
|
|
12
|
+
this.vite = vite;
|
|
13
|
+
this.#devServer = this.vite.getDevServer();
|
|
14
|
+
}
|
|
15
|
+
#devServer;
|
|
16
|
+
/**
|
|
17
|
+
* Handles HTTP requests by proxying them to the Vite dev server when appropriate
|
|
18
|
+
*
|
|
19
|
+
* @param request - The HTTP request object from AdonisJS context
|
|
20
|
+
* @param response - The HTTP response object from AdonisJS context
|
|
21
|
+
* @param next - Function to call the next middleware in the chain
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* await middleware.handle(ctx, next)
|
|
25
|
+
*/
|
|
26
|
+
async handle({ request, response }, next) {
|
|
27
|
+
if (!this.#devServer) {
|
|
28
|
+
return next();
|
|
29
|
+
}
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
function done(error) {
|
|
32
|
+
response.response.removeListener("finish", done);
|
|
33
|
+
if (error) {
|
|
34
|
+
reject(error);
|
|
35
|
+
} else {
|
|
36
|
+
resolve();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
response.response.addListener("finish", done);
|
|
40
|
+
response.relayHeaders();
|
|
41
|
+
this.#devServer.middlewares.handle(request.request, response.response, async () => {
|
|
42
|
+
response.response.removeListener("finish", done);
|
|
43
|
+
try {
|
|
44
|
+
await next();
|
|
45
|
+
done();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
done(error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
ViteMiddleware
|
|
56
|
+
};
|
package/build/index.js
CHANGED
|
@@ -5,29 +5,89 @@ declare module '@adonisjs/core/types' {
|
|
|
5
5
|
vite: Vite;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* AdonisJS service provider for integrating Vite build tool and development server
|
|
10
|
+
*
|
|
11
|
+
* Handles lifecycle management of Vite integration including:
|
|
12
|
+
* - Registering Vite service in the container
|
|
13
|
+
* - Setting up Edge.js plugin for template integration
|
|
14
|
+
* - Managing development server startup/shutdown
|
|
15
|
+
* - Configuring CSP keywords for @adonisjs/shield
|
|
16
|
+
*/
|
|
8
17
|
export default class ViteProvider {
|
|
9
18
|
#private;
|
|
10
19
|
protected app: ApplicationService;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new ViteProvider instance
|
|
22
|
+
*
|
|
23
|
+
* @param app - The AdonisJS application service instance
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const provider = new ViteProvider(app)
|
|
27
|
+
*/
|
|
11
28
|
constructor(app: ApplicationService);
|
|
12
29
|
/**
|
|
13
|
-
* Registers
|
|
30
|
+
* Registers the Vite Edge.js plugin if Edge.js is available in the application
|
|
31
|
+
*
|
|
32
|
+
* Adds global helpers and custom tags (@vite, @viteReactRefresh) to Edge templates.
|
|
33
|
+
* Only registers the plugin if the application is using Edge.js.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* await provider.registerEdgePlugin()
|
|
37
|
+
* // Enables @vite('app.js') in Edge templates
|
|
14
38
|
*/
|
|
15
39
|
protected registerEdgePlugin(): Promise<void>;
|
|
16
40
|
/**
|
|
17
|
-
* Registers
|
|
41
|
+
* Registers Content Security Policy keywords when @adonisjs/shield is installed
|
|
42
|
+
*
|
|
43
|
+
* Adds the '@viteUrl' keyword for CSP directives that returns the Vite assets URL
|
|
44
|
+
* when it's an HTTP/HTTPS URL, or an empty string otherwise.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* await provider.registerShieldKeywords()
|
|
48
|
+
* // Enables @viteUrl in CSP directives
|
|
18
49
|
*/
|
|
19
50
|
protected registerShieldKeywords(): Promise<void>;
|
|
20
51
|
/**
|
|
21
|
-
*
|
|
52
|
+
* Registers Vite service and middleware bindings in the IoC container
|
|
53
|
+
*
|
|
54
|
+
* Creates a Vite instance using configuration and determines whether
|
|
55
|
+
* the development server should run based on environment and manifest file presence.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* provider.register()
|
|
59
|
+
* // Vite service is now available via container.make('vite')
|
|
22
60
|
*/
|
|
23
61
|
register(): void;
|
|
24
62
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
63
|
+
* Boots the Vite provider by registering plugins and integrations
|
|
64
|
+
*
|
|
65
|
+
* Registers Edge.js plugin and Shield CSP keywords if the respective
|
|
66
|
+
* packages are available in the application.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* await provider.boot()
|
|
27
70
|
*/
|
|
28
71
|
boot(): Promise<void>;
|
|
29
72
|
/**
|
|
30
|
-
*
|
|
73
|
+
* Starts the Vite development server when the application is ready
|
|
74
|
+
*
|
|
75
|
+
* Only starts the server if running in development/test mode and
|
|
76
|
+
* no manifest file exists (indicating development mode).
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* await provider.ready()
|
|
80
|
+
* // Dev server starts on configured port
|
|
81
|
+
*/
|
|
82
|
+
ready(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Gracefully stops the Vite development server during application shutdown
|
|
85
|
+
*
|
|
86
|
+
* Only attempts to stop the server if it was started during the ready phase.
|
|
87
|
+
* Ensures clean shutdown of the development server and its resources.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* await provider.shutdown()
|
|
31
91
|
*/
|
|
32
92
|
shutdown(): Promise<void>;
|
|
33
93
|
}
|
|
@@ -1,19 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Vite
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-47LUVDLW.js";
|
|
4
4
|
import {
|
|
5
5
|
ViteMiddleware
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-AF6PV64J.js";
|
|
7
7
|
import "../chunk-ZCQTQOMI.js";
|
|
8
8
|
|
|
9
9
|
// providers/vite_provider.ts
|
|
10
10
|
var ViteProvider = class {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new ViteProvider instance
|
|
13
|
+
*
|
|
14
|
+
* @param app - The AdonisJS application service instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const provider = new ViteProvider(app)
|
|
18
|
+
*/
|
|
11
19
|
constructor(app) {
|
|
12
20
|
this.app = app;
|
|
13
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Flag indicating whether the Vite development server should be started
|
|
24
|
+
* Set to true when manifest file doesn't exist and running in web/test environment
|
|
25
|
+
*/
|
|
14
26
|
#shouldRunViteDevServer = false;
|
|
15
27
|
/**
|
|
16
|
-
* Registers
|
|
28
|
+
* Registers the Vite Edge.js plugin if Edge.js is available in the application
|
|
29
|
+
*
|
|
30
|
+
* Adds global helpers and custom tags (@vite, @viteReactRefresh) to Edge templates.
|
|
31
|
+
* Only registers the plugin if the application is using Edge.js.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* await provider.registerEdgePlugin()
|
|
35
|
+
* // Enables @vite('app.js') in Edge templates
|
|
17
36
|
*/
|
|
18
37
|
async registerEdgePlugin() {
|
|
19
38
|
if (this.app.usingEdgeJS) {
|
|
@@ -24,7 +43,14 @@ var ViteProvider = class {
|
|
|
24
43
|
}
|
|
25
44
|
}
|
|
26
45
|
/**
|
|
27
|
-
* Registers
|
|
46
|
+
* Registers Content Security Policy keywords when @adonisjs/shield is installed
|
|
47
|
+
*
|
|
48
|
+
* Adds the '@viteUrl' keyword for CSP directives that returns the Vite assets URL
|
|
49
|
+
* when it's an HTTP/HTTPS URL, or an empty string otherwise.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* await provider.registerShieldKeywords()
|
|
53
|
+
* // Enables @viteUrl in CSP directives
|
|
28
54
|
*/
|
|
29
55
|
async registerShieldKeywords() {
|
|
30
56
|
let cspKeywords = null;
|
|
@@ -46,23 +72,47 @@ var ViteProvider = class {
|
|
|
46
72
|
});
|
|
47
73
|
}
|
|
48
74
|
/**
|
|
49
|
-
*
|
|
75
|
+
* Registers Vite service and middleware bindings in the IoC container
|
|
76
|
+
*
|
|
77
|
+
* Creates a Vite instance using configuration and determines whether
|
|
78
|
+
* the development server should run based on environment and manifest file presence.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* provider.register()
|
|
82
|
+
* // Vite service is now available via container.make('vite')
|
|
50
83
|
*/
|
|
51
84
|
register() {
|
|
52
85
|
const appEnvironment = this.app.getEnvironment();
|
|
53
86
|
const isWebOrTestEnvironment = appEnvironment === "web" || appEnvironment === "test";
|
|
54
87
|
const vite = new Vite(this.app.config.get("vite"));
|
|
55
88
|
this.#shouldRunViteDevServer = !vite.hasManifestFile && isWebOrTestEnvironment;
|
|
56
|
-
this.app.container.
|
|
89
|
+
this.app.container.singleton("vite", () => vite);
|
|
57
90
|
this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite));
|
|
58
91
|
}
|
|
59
92
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
93
|
+
* Boots the Vite provider by registering plugins and integrations
|
|
94
|
+
*
|
|
95
|
+
* Registers Edge.js plugin and Shield CSP keywords if the respective
|
|
96
|
+
* packages are available in the application.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* await provider.boot()
|
|
62
100
|
*/
|
|
63
101
|
async boot() {
|
|
64
102
|
await this.registerEdgePlugin();
|
|
65
103
|
await this.registerShieldKeywords();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Starts the Vite development server when the application is ready
|
|
107
|
+
*
|
|
108
|
+
* Only starts the server if running in development/test mode and
|
|
109
|
+
* no manifest file exists (indicating development mode).
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* await provider.ready()
|
|
113
|
+
* // Dev server starts on configured port
|
|
114
|
+
*/
|
|
115
|
+
async ready() {
|
|
66
116
|
if (!this.#shouldRunViteDevServer) {
|
|
67
117
|
return;
|
|
68
118
|
}
|
|
@@ -70,7 +120,13 @@ var ViteProvider = class {
|
|
|
70
120
|
await vite.createDevServer();
|
|
71
121
|
}
|
|
72
122
|
/**
|
|
73
|
-
*
|
|
123
|
+
* Gracefully stops the Vite development server during application shutdown
|
|
124
|
+
*
|
|
125
|
+
* Only attempts to stop the server if it was started during the ready phase.
|
|
126
|
+
* Ensures clean shutdown of the development server and its resources.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* await provider.shutdown()
|
|
74
130
|
*/
|
|
75
131
|
async shutdown() {
|
|
76
132
|
if (!this.#shouldRunViteDevServer) {
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import type { ConfigEnv, Plugin, UserConfig } from 'vite';
|
|
2
2
|
import type { PluginFullOptions } from './types.ts';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Resolves the base URL for Vite configuration based on command and options
|
|
5
|
+
*
|
|
6
|
+
* @param config - User-provided Vite configuration
|
|
7
|
+
* @param options - Plugin options containing assetsUrl
|
|
8
|
+
* @param command - Vite command being executed ('build' or 'serve')
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const base = resolveBase(userConfig, { assetsUrl: '/assets' }, 'build')
|
|
12
|
+
* // Returns: '/assets/' for build, '/' for serve
|
|
5
13
|
*/
|
|
6
14
|
export declare function resolveBase(config: UserConfig, options: PluginFullOptions, command: 'build' | 'serve'): string;
|
|
7
15
|
/**
|
|
8
|
-
* Vite
|
|
16
|
+
* Merges user Vite configuration with AdonisJS-specific defaults and requirements
|
|
17
|
+
*
|
|
18
|
+
* @param options - Plugin options containing build directory and entry points
|
|
19
|
+
* @param userConfig - User-provided Vite configuration
|
|
20
|
+
* @param command - Vite environment command
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const mergedConfig = configHook(pluginOptions, userViteConfig, { command: 'build' })
|
|
9
24
|
*/
|
|
10
25
|
export declare function configHook(options: PluginFullOptions, userConfig: UserConfig, { command }: ConfigEnv): UserConfig;
|
|
11
26
|
/**
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ViteOptions } from './types.ts';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Creates a complete Vite configuration by merging provided options with sensible defaults
|
|
4
|
+
*
|
|
5
|
+
* @param config - Partial Vite configuration options to override defaults
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const viteConfig = defineConfig({
|
|
9
|
+
* assetsUrl: '/static',
|
|
10
|
+
* buildDirectory: 'dist'
|
|
11
|
+
* })
|
|
4
12
|
*/
|
|
5
13
|
export declare function defineConfig(config: Partial<ViteOptions>): ViteOptions;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import type { PluginFn } from 'edge.js/types';
|
|
2
2
|
import type { Vite } from '../vite.ts';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Creates an Edge.js plugin that integrates Vite functionality into templates
|
|
5
|
+
*
|
|
6
|
+
* Registers global helpers and custom tags (@vite, @viteReactRefresh) for use in Edge templates.
|
|
7
|
+
* Provides access to asset paths and HMR functionality within template rendering.
|
|
8
|
+
*
|
|
9
|
+
* @param vite - The Vite instance to integrate with Edge templates
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const plugin = edgePluginVite(viteInstance)
|
|
13
|
+
* edge.use(plugin)
|
|
14
|
+
*
|
|
15
|
+
* // In templates:
|
|
16
|
+
* // @vite('app.js')
|
|
17
|
+
* // @viteReactRefresh({ nonce: 'abc123' })
|
|
6
18
|
*/
|
|
7
19
|
export declare const edgePluginVite: (vite: Vite) => PluginFn<undefined>;
|
package/build/src/utils.d.ts
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns a new array with unique items by the
|
|
2
|
+
* Returns a new array with unique items filtered by the specified key
|
|
3
|
+
*
|
|
4
|
+
* @param array - The array to filter for unique items
|
|
5
|
+
* @param key - The key to use for uniqueness comparison
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const users = [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 1, name: 'John' }]
|
|
9
|
+
* const unique = uniqBy(users, 'id')
|
|
10
|
+
* // Returns: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
|
|
3
11
|
*/
|
|
4
12
|
export declare function uniqBy<T>(array: T[], key: keyof T): T[];
|
|
5
13
|
/**
|
|
6
|
-
*
|
|
14
|
+
* Converts an object of HTML attributes to a valid HTML attribute string
|
|
15
|
+
*
|
|
16
|
+
* @param attributes - Object containing HTML attributes where values can be strings or booleans
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const attrs = makeAttributes({ class: 'btn', disabled: true, hidden: false })
|
|
20
|
+
* // Returns: 'class="btn" disabled'
|
|
7
21
|
*/
|
|
8
22
|
export declare function makeAttributes(attributes: Record<string, string | boolean>): string;
|
|
9
23
|
/**
|
|
10
|
-
*
|
|
24
|
+
* Adds a trailing slash to a URL if it doesn't already have one
|
|
25
|
+
*
|
|
26
|
+
* @param url - The URL string to process
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* addTrailingSlash('/api') // Returns: '/api/'
|
|
30
|
+
* addTrailingSlash('/api/') // Returns: '/api/'
|
|
11
31
|
*/
|
|
12
32
|
export declare const addTrailingSlash: (url: string) => string;
|
package/build/src/vite.d.ts
CHANGED
|
@@ -7,50 +7,144 @@ import type { AdonisViteElement, ViteOptions } from './types.ts';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class Vite {
|
|
9
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Indicates whether the Vite manifest file exists on disk
|
|
12
|
+
*/
|
|
10
13
|
hasManifestFile: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new Vite instance for managing asset compilation and serving
|
|
16
|
+
*
|
|
17
|
+
* @param options - Configuration options for Vite integration
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const vite = new Vite({
|
|
21
|
+
* buildDirectory: 'build',
|
|
22
|
+
* assetsUrl: '/assets',
|
|
23
|
+
* manifestFile: 'build/manifest.json'
|
|
24
|
+
* })
|
|
25
|
+
*/
|
|
11
26
|
constructor(options: ViteOptions);
|
|
12
27
|
/**
|
|
13
|
-
* Generate tags for the entry points
|
|
28
|
+
* Generate HTML tags (script and link) for the specified entry points
|
|
29
|
+
*
|
|
30
|
+
* In development mode, includes HMR script and dynamically discovers CSS files.
|
|
31
|
+
* In production mode, uses the manifest file to generate optimized tags with preloading.
|
|
32
|
+
*
|
|
33
|
+
* @param entryPoints - Single entry point or array of entry points to generate tags for
|
|
34
|
+
* @param attributes - Additional HTML attributes to apply to the generated tags
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Generate tags for a single entry point
|
|
38
|
+
* const tags = await vite.generateEntryPointsTags('app.js')
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Generate tags for multiple entry points with custom attributes
|
|
42
|
+
* const tags = await vite.generateEntryPointsTags(
|
|
43
|
+
* ['app.js', 'admin.js'],
|
|
44
|
+
* { defer: true }
|
|
45
|
+
* )
|
|
14
46
|
*/
|
|
15
47
|
generateEntryPointsTags(entryPoints: string[] | string, attributes?: Record<string, any>): Promise<AdonisViteElement[]>;
|
|
16
48
|
/**
|
|
17
|
-
* Returns the
|
|
49
|
+
* Returns the base URL for serving static assets
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const url = vite.assetsUrl()
|
|
53
|
+
* // Returns: '/assets' or '/build' depending on configuration
|
|
18
54
|
*/
|
|
19
55
|
assetsUrl(): string | undefined;
|
|
20
56
|
/**
|
|
21
|
-
* Returns path to a
|
|
57
|
+
* Returns the full URL path to a specific asset file
|
|
58
|
+
*
|
|
59
|
+
* In development mode, returns the asset path with leading slash.
|
|
60
|
+
* In production mode, uses the manifest file to return the versioned/hashed asset URL.
|
|
61
|
+
*
|
|
62
|
+
* @param asset - The relative path to the asset file
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const path = vite.assetPath('images/logo.png')
|
|
66
|
+
* // Dev: '/images/logo.png'
|
|
67
|
+
* // Prod: '/assets/images/logo-abc123.png'
|
|
22
68
|
*/
|
|
23
69
|
assetPath(asset: string): string;
|
|
24
70
|
/**
|
|
25
|
-
* Returns the manifest file contents
|
|
71
|
+
* Returns the parsed Vite manifest file contents
|
|
26
72
|
*
|
|
27
|
-
*
|
|
73
|
+
* The manifest file contains information about compiled assets including
|
|
74
|
+
* file paths, integrity hashes, and import dependencies.
|
|
75
|
+
*
|
|
76
|
+
* @throws Will throw an exception when running in development mode
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const manifest = vite.manifest()
|
|
80
|
+
* console.log(manifest['app.js'].file) // 'assets/app-abc123.js'
|
|
28
81
|
*/
|
|
29
82
|
manifest(): Manifest;
|
|
30
83
|
/**
|
|
31
|
-
*
|
|
84
|
+
* Creates and initializes the Vite development server
|
|
85
|
+
*
|
|
86
|
+
* Lazy loads Vite APIs to avoid importing them in production.
|
|
87
|
+
* The server runs in middleware mode and is configured for custom app integration.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Additional Vite configuration options to merge with defaults
|
|
32
90
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
91
|
+
* @example
|
|
92
|
+
* await vite.createDevServer({
|
|
93
|
+
* root: './src',
|
|
94
|
+
* server: { port: 3000 }
|
|
95
|
+
* })
|
|
35
96
|
*/
|
|
36
97
|
createDevServer(options?: InlineConfig): Promise<void>;
|
|
37
98
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* it
|
|
99
|
+
* Creates a server-side module runner for executing modules in Node.js context
|
|
100
|
+
*
|
|
101
|
+
* Only available in development mode as it requires the Vite dev server.
|
|
102
|
+
* Useful for server-side rendering and module transformation.
|
|
103
|
+
*
|
|
104
|
+
* @param options - Configuration options for the module runner
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* const runner = await vite.createModuleRunner({
|
|
108
|
+
* hmr: { port: 24678 }
|
|
109
|
+
* })
|
|
110
|
+
* const mod = await runner.import('./app.js')
|
|
41
111
|
*/
|
|
42
112
|
createModuleRunner(options?: ServerModuleRunnerOptions): Promise<ModuleRunner>;
|
|
43
113
|
/**
|
|
44
|
-
*
|
|
114
|
+
* Gracefully stops the Vite development server
|
|
115
|
+
*
|
|
116
|
+
* Waits for the server creation promise to complete before closing.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* await vite.stopDevServer()
|
|
45
120
|
*/
|
|
46
121
|
stopDevServer(): Promise<void>;
|
|
47
122
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
123
|
+
* Returns the Vite development server instance
|
|
124
|
+
*
|
|
125
|
+
* Only available in development mode after calling createDevServer().
|
|
126
|
+
* Returns undefined in production or if the server hasn't been created yet.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* const server = vite.getDevServer()
|
|
130
|
+
* if (server) {
|
|
131
|
+
* console.log('Dev server is running on', server.config.server.port)
|
|
132
|
+
* }
|
|
50
133
|
*/
|
|
51
134
|
getDevServer(): ViteDevServer | undefined;
|
|
52
135
|
/**
|
|
53
|
-
*
|
|
136
|
+
* Generates the React Hot Module Replacement (HMR) script for development
|
|
137
|
+
*
|
|
138
|
+
* Only returns a script element in development mode. In production mode,
|
|
139
|
+
* returns null since HMR is not needed.
|
|
140
|
+
*
|
|
141
|
+
* @param attributes - Additional HTML attributes to apply to the script tag
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const hmrScript = vite.getReactHmrScript({ async: true })
|
|
145
|
+
* if (hmrScript) {
|
|
146
|
+
* console.log(hmrScript.toString()) // <script type="module" async>...</script>
|
|
147
|
+
* }
|
|
54
148
|
*/
|
|
55
149
|
getReactHmrScript(attributes?: Record<string, any>): AdonisViteElement | null;
|
|
56
150
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
1
|
import type { NextFn } from '@adonisjs/core/types/http';
|
|
2
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
3
3
|
import type { Vite } from './vite.ts';
|
|
4
4
|
/**
|
|
5
|
+
* Middleware for proxying requests between AdonisJS and Vite development server
|
|
6
|
+
*
|
|
5
7
|
* Since Vite dev server is integrated within the AdonisJS process, this
|
|
6
8
|
* middleware is used to proxy the requests to it.
|
|
7
9
|
*
|
|
@@ -12,6 +14,24 @@ import type { Vite } from './vite.ts';
|
|
|
12
14
|
export default class ViteMiddleware {
|
|
13
15
|
#private;
|
|
14
16
|
protected vite: Vite;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new ViteMiddleware instance
|
|
19
|
+
*
|
|
20
|
+
* @param vite - The Vite instance containing the dev server
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const middleware = new ViteMiddleware(viteInstance)
|
|
24
|
+
*/
|
|
15
25
|
constructor(vite: Vite);
|
|
26
|
+
/**
|
|
27
|
+
* Handles HTTP requests by proxying them to the Vite dev server when appropriate
|
|
28
|
+
*
|
|
29
|
+
* @param request - The HTTP request object from AdonisJS context
|
|
30
|
+
* @param response - The HTTP response object from AdonisJS context
|
|
31
|
+
* @param next - Function to call the next middleware in the chain
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* await middleware.handle(ctx, next)
|
|
35
|
+
*/
|
|
16
36
|
handle({ request, response }: HttpContext, next: NextFn): Promise<any>;
|
|
17
37
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/vite",
|
|
3
3
|
"description": "Vite plugin for AdonisJS",
|
|
4
|
-
"version": "5.0
|
|
4
|
+
"version": "5.1.0-next.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"docs": "typedoc"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@adonisjs/assembler": "^8.0.0-next.
|
|
48
|
-
"@adonisjs/core": "^7.0.0-next.
|
|
47
|
+
"@adonisjs/assembler": "^8.0.0-next.14",
|
|
48
|
+
"@adonisjs/core": "^7.0.0-next.7",
|
|
49
49
|
"@adonisjs/eslint-config": "^3.0.0-next.1",
|
|
50
50
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
51
51
|
"@adonisjs/session": "^8.0.0-next.0",
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
"@japa/snapshot": "^2.0.9",
|
|
58
58
|
"@poppinss/ts-exec": "^1.4.1",
|
|
59
59
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
60
|
-
"@types/node": "^24.
|
|
60
|
+
"@types/node": "^24.9.1",
|
|
61
61
|
"@types/supertest": "^6.0.3",
|
|
62
62
|
"c8": "^10.1.3",
|
|
63
63
|
"copyfiles": "^2.4.1",
|
|
64
64
|
"cross-env": "^10.1.0",
|
|
65
65
|
"del-cli": "^7.0.0",
|
|
66
66
|
"edge.js": "^6.3.0",
|
|
67
|
-
"eslint": "^9.
|
|
67
|
+
"eslint": "^9.38.0",
|
|
68
68
|
"prettier": "^3.6.2",
|
|
69
69
|
"release-it": "^19.0.5",
|
|
70
70
|
"supertest": "^7.1.4",
|
|
71
71
|
"tsup": "^8.5.0",
|
|
72
|
-
"typedoc": "^0.28.
|
|
72
|
+
"typedoc": "^0.28.14",
|
|
73
73
|
"typescript": "~5.9.3",
|
|
74
|
-
"vite": "^7.1.
|
|
74
|
+
"vite": "^7.1.11"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@poppinss/utils": "^7.0.0-next.3",
|
package/build/chunk-FDN2SRQF.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// src/vite_middleware.ts
|
|
2
|
-
var ViteMiddleware = class {
|
|
3
|
-
constructor(vite) {
|
|
4
|
-
this.vite = vite;
|
|
5
|
-
this.#devServer = this.vite.getDevServer();
|
|
6
|
-
}
|
|
7
|
-
#devServer;
|
|
8
|
-
async handle({ request, response }, next) {
|
|
9
|
-
if (!this.#devServer) {
|
|
10
|
-
return next();
|
|
11
|
-
}
|
|
12
|
-
if (this.#devServer.config.server.cors === false) {
|
|
13
|
-
response.relayHeaders();
|
|
14
|
-
}
|
|
15
|
-
await new Promise((resolve) => {
|
|
16
|
-
this.#devServer.middlewares.handle(request.request, response.response, () => {
|
|
17
|
-
return resolve(next());
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
ViteMiddleware
|
|
25
|
-
};
|