@adonisjs/vite 5.1.1 → 6.0.0-next.1
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/index.js +1 -1
- package/build/providers/vite_provider.js +2 -2
- package/build/src/client/main.js +936 -6
- package/build/src/client/reload.d.ts +13 -0
- package/build/src/client/resolve_assets.d.ts +20 -0
- package/build/src/client/types.d.ts +26 -1
- package/build/src/hooks/build_hook.js +10 -1
- package/build/src/server_modules/bundled_module_resolver.d.ts +17 -0
- package/build/src/server_modules/dev_module_runner.d.ts +25 -0
- package/build/src/server_modules/server_module_loader.d.ts +25 -0
- package/build/src/types.d.ts +32 -0
- package/build/src/vite.d.ts +22 -1
- package/build/src/vite_middleware.d.ts +1 -0
- package/build/src/vite_middleware.js +1 -1
- package/build/{vite-DDpuL-Eo.js → vite-De-RhsJ1.js} +163 -5
- package/build/{vite_middleware-Bszg_DDr.js → vite_middleware-CuOBHhnt.js} +4 -3
- package/package.json +18 -17
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Plugin } from 'vite';
|
|
2
|
+
export interface ReloadOptions {
|
|
3
|
+
delay?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Returns a Vite plugin that triggers a full browser reload whenever any file
|
|
7
|
+
* matching the supplied glob patterns changes. Patterns are resolved relative
|
|
8
|
+
* to the Vite project root.
|
|
9
|
+
*
|
|
10
|
+
* Replaces the previous `vite-plugin-restart` dependency. Only the reload
|
|
11
|
+
* (browser refresh) feature is implemented — server restart is not.
|
|
12
|
+
*/
|
|
13
|
+
export declare function reload(patterns: string | string[], options?: ReloadOptions): Plugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { PluginOptions } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a plugin that emits user-supplied files into the build output.
|
|
5
|
+
*
|
|
6
|
+
* `chunks` are passed to Vite's `emitFile({ type: 'chunk' })` after glob
|
|
7
|
+
* expansion. They are processed by the bundler and surface in the manifest
|
|
8
|
+
* with hashed filenames.
|
|
9
|
+
*
|
|
10
|
+
* `assets` are emitted as raw `type: 'asset'` files (no glob expansion —
|
|
11
|
+
* exact paths only) so the original source content is preserved verbatim.
|
|
12
|
+
* The `originalFileName` field tells Vite to use the source path as the
|
|
13
|
+
* manifest key, so templates can resolve them via
|
|
14
|
+
* `vite.assetPath('resources/images/logo.png')` without any post-build
|
|
15
|
+
* manifest rewriting.
|
|
16
|
+
*
|
|
17
|
+
* Returns an empty array (no-op) when neither chunks nor assets are
|
|
18
|
+
* configured.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveAssets(input: PluginOptions['assets']): Plugin[];
|
|
@@ -22,5 +22,30 @@ export interface PluginOptions {
|
|
|
22
22
|
* @default 'public/assets'
|
|
23
23
|
*/
|
|
24
24
|
buildDirectory?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Server-side entrypoints bundled into the SSR build output. Each
|
|
27
|
+
* entry is emitted as a single bundle (no hash, no shared chunks)
|
|
28
|
+
* under `<buildDirectory>/server/<name>.js` and becomes loadable
|
|
29
|
+
* through `vite.loadServerModule()` at runtime.
|
|
30
|
+
*
|
|
31
|
+
* Paths are relative to the project root.
|
|
32
|
+
*/
|
|
33
|
+
serverEntrypoints?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Additional files to include in the build that are not imported by the
|
|
36
|
+
* entrypoints.
|
|
37
|
+
*
|
|
38
|
+
* - When passed as a `string[]`, every entry is treated as a chunk: glob
|
|
39
|
+
* patterns are expanded and each matching file is emitted via Vite's
|
|
40
|
+
* `emitFile({ type: 'chunk' })`.
|
|
41
|
+
* - When passed as `{ chunks?, assets? }`, `chunks` behaves identically
|
|
42
|
+
* to the array form, while `assets` files are emitted as raw assets
|
|
43
|
+
* (no glob support, exact paths only) and the manifest is rewritten so
|
|
44
|
+
* the manifest key matches the source path.
|
|
45
|
+
*/
|
|
46
|
+
assets?: string[] | {
|
|
47
|
+
chunks?: string[];
|
|
48
|
+
assets?: string[];
|
|
49
|
+
};
|
|
25
50
|
}
|
|
26
|
-
export type PluginFullOptions = Required<PluginOptions
|
|
51
|
+
export type PluginFullOptions = Required<Omit<PluginOptions, 'assets'>>;
|
|
@@ -8,8 +8,17 @@ import { createBuilder } from "vite";
|
|
|
8
8
|
* The hook is responsible for launching a Vite multi-build process.
|
|
9
9
|
*/
|
|
10
10
|
var build_hook_default = hooks.buildStarting(async (parent) => {
|
|
11
|
+
/**
|
|
12
|
+
* Vite's CLI sets NODE_ENV to 'production' automatically when running
|
|
13
|
+
* `vite build`, but the programmatic `createBuilder` API does not.
|
|
14
|
+
* Without this, framework plugins (React, Vue, MDX, …) emit dev-only
|
|
15
|
+
* code paths in the production bundle.
|
|
16
|
+
*
|
|
17
|
+
* See https://github.com/remix-run/remix/issues/4081
|
|
18
|
+
*/
|
|
19
|
+
process.env.NODE_ENV = "production";
|
|
11
20
|
parent.ui.logger.info("building assets with vite");
|
|
12
|
-
await (await createBuilder({},
|
|
21
|
+
await (await createBuilder({}, false)).buildApp();
|
|
13
22
|
});
|
|
14
23
|
//#endregion
|
|
15
24
|
export { build_hook_default as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves and imports server-side modules from the production SSR build.
|
|
3
|
+
*
|
|
4
|
+
* In production there is no Vite dev server — entrypoints declared as
|
|
5
|
+
* `serverEntrypoints` are pre-built into `<buildDirectory>/server` and
|
|
6
|
+
* recorded in `<buildDirectory>/server/.vite/manifest.json`. The
|
|
7
|
+
* resolver reads that manifest to map an entry source path to the
|
|
8
|
+
* emitted bundle file, then imports it through Node's native `import()`.
|
|
9
|
+
*
|
|
10
|
+
* Imports are cached per entry so repeated calls reuse the same module
|
|
11
|
+
* instance and side-effects only run once.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BundledModuleResolver {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(buildDirectory: string);
|
|
16
|
+
import<T>(entry: string): Promise<T>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ViteDevServer } from 'vite';
|
|
2
|
+
import type { ModuleRunner } from 'vite/module-runner';
|
|
3
|
+
import type { LoadServerModuleOptions } from '../types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Hosts the Vite `ModuleRunner` used to evaluate server-side modules in
|
|
6
|
+
* development mode.
|
|
7
|
+
*
|
|
8
|
+
* Owns a single shared runner across all `loadServerModule` calls, and
|
|
9
|
+
* detects Vite dev server restarts (which replace `server.environments.ssr`
|
|
10
|
+
* with a fresh instance) so the stale runner is closed and recreated.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DevModuleRunner {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(createRunner: () => Promise<ModuleRunner>);
|
|
15
|
+
/**
|
|
16
|
+
* Imports a module through the runner. Recreates the runner if the
|
|
17
|
+
* dev server's SSR environment was swapped underneath us.
|
|
18
|
+
*/
|
|
19
|
+
import<T>(server: ViteDevServer, entry: string, opts: LoadServerModuleOptions): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Closes the runner, if any. Safe to call when no runner has been
|
|
22
|
+
* created yet.
|
|
23
|
+
*/
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ViteDevServer } from 'vite';
|
|
2
|
+
import type { ModuleRunner } from 'vite/module-runner';
|
|
3
|
+
import type { LoadServerModuleOptions } from '../types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Public entry point for loading server-side modules processed by Vite.
|
|
6
|
+
*
|
|
7
|
+
* Picks between two collaborators based on whether the Vite dev server
|
|
8
|
+
* is running:
|
|
9
|
+
*
|
|
10
|
+
* - In development, delegates to {@link DevModuleRunner} which evaluates
|
|
11
|
+
* the entry through Vite's `ModuleRunner`, with HMR-driven cache
|
|
12
|
+
* invalidation.
|
|
13
|
+
* - In production, delegates to {@link BundledModuleResolver} which
|
|
14
|
+
* imports the pre-built bundle from disk.
|
|
15
|
+
*
|
|
16
|
+
* Entry strings are passed through verbatim to mirror how client
|
|
17
|
+
* `entrypoints` are handled — the caller is responsible for using the
|
|
18
|
+
* exact string declared in `serverEntrypoints`.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ServerModuleLoader {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(getDevServer: () => ViteDevServer | undefined, buildDirectory: string, createRunner: () => Promise<ModuleRunner>);
|
|
23
|
+
load<T>(entry: string, opts?: LoadServerModuleOptions): Promise<T>;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
package/build/src/types.d.ts
CHANGED
|
@@ -54,3 +54,35 @@ export interface ViteOptions {
|
|
|
54
54
|
*/
|
|
55
55
|
scriptAttributes?: SetAttributes;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Augmentable map for typing entries passed to `vite.loadServerModule`.
|
|
59
|
+
* Apps and packages merge into this interface to associate entrypoint
|
|
60
|
+
* paths with the shape of their default exports.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* declare module '@adonisjs/vite/types' {
|
|
64
|
+
* interface ServerModuleMap {
|
|
65
|
+
* 'inertia/app/ssr.ts': typeof import('../inertia/app/ssr.ts')
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
*/
|
|
69
|
+
export interface ServerModuleMap {
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Options accepted by `vite.loadServerModule`.
|
|
73
|
+
*/
|
|
74
|
+
export interface LoadServerModuleOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Clear the module runner cache before importing in dev mode.
|
|
77
|
+
*
|
|
78
|
+
* Defaults to `false` — Vite's HMR pushes invalidations into the
|
|
79
|
+
* runner, so cached modules are already kept fresh on file change.
|
|
80
|
+
* Set to `true` only when the entrypoint registers top-level state
|
|
81
|
+
* that must be reset on every load.
|
|
82
|
+
*
|
|
83
|
+
* Has no effect in production (bundled imports are always cached).
|
|
84
|
+
*
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
fresh?: boolean;
|
|
88
|
+
}
|
package/build/src/vite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ModuleRunner } from 'vite/module-runner';
|
|
2
2
|
import type { Manifest, InlineConfig, ViteDevServer, ServerModuleRunnerOptions } from 'vite';
|
|
3
|
-
import type { AdonisViteElement, ViteOptions } from './types.ts';
|
|
3
|
+
import type { AdonisViteElement, LoadServerModuleOptions, ServerModuleMap, ViteOptions } from './types.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Vite class exposes the APIs to generate tags and URLs for
|
|
6
6
|
* assets processed using vite.
|
|
@@ -111,6 +111,27 @@ export declare class Vite {
|
|
|
111
111
|
* const mod = await runner.import('./app.js')
|
|
112
112
|
*/
|
|
113
113
|
createModuleRunner(options?: ServerModuleRunnerOptions): Promise<ModuleRunner>;
|
|
114
|
+
/**
|
|
115
|
+
* Loads a server-side module that has been processed by Vite.
|
|
116
|
+
*
|
|
117
|
+
* In development, the entry is evaluated through Vite's `ModuleRunner`,
|
|
118
|
+
* giving full TypeScript / JSX / plugin support and HMR-driven cache
|
|
119
|
+
* invalidation. In production, the entry is imported from the
|
|
120
|
+
* pre-built SSR bundle on disk.
|
|
121
|
+
*
|
|
122
|
+
* The entry path must be declared in `serverEntrypoints` for the
|
|
123
|
+
* production import to succeed — otherwise the bundle won't exist.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const mod = await vite.loadServerModule('inertia/app/ssr.ts')
|
|
127
|
+
* const html = await mod.default(payload)
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* // Force re-evaluation (clear runner cache before import)
|
|
131
|
+
* await vite.loadServerModule('emails/welcome.ts', { fresh: true })
|
|
132
|
+
*/
|
|
133
|
+
loadServerModule<K extends keyof ServerModuleMap>(entry: K, opts?: LoadServerModuleOptions): Promise<ServerModuleMap[K]>;
|
|
134
|
+
loadServerModule<T = unknown>(entry: string, opts?: LoadServerModuleOptions): Promise<T>;
|
|
114
135
|
/**
|
|
115
136
|
* Gracefully stops the Vite development server
|
|
116
137
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as ViteMiddleware } from "../vite_middleware-
|
|
1
|
+
import { t as ViteMiddleware } from "../vite_middleware-CuOBHhnt.js";
|
|
2
2
|
export { ViteMiddleware as default };
|
|
@@ -2,6 +2,148 @@ import { n as makeAttributes, r as uniqBy } from "./utils-CdZpa_tV.js";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import string from "@poppinss/utils/string";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
//#region src/server_modules/dev_module_runner.ts
|
|
7
|
+
/**
|
|
8
|
+
* Hosts the Vite `ModuleRunner` used to evaluate server-side modules in
|
|
9
|
+
* development mode.
|
|
10
|
+
*
|
|
11
|
+
* Owns a single shared runner across all `loadServerModule` calls, and
|
|
12
|
+
* detects Vite dev server restarts (which replace `server.environments.ssr`
|
|
13
|
+
* with a fresh instance) so the stale runner is closed and recreated.
|
|
14
|
+
*/
|
|
15
|
+
var DevModuleRunner = class {
|
|
16
|
+
/**
|
|
17
|
+
* Shared module runner. Lazy-created on first import.
|
|
18
|
+
*/
|
|
19
|
+
#runner;
|
|
20
|
+
/**
|
|
21
|
+
* Reference to the SSR environment the current runner was created from.
|
|
22
|
+
* When Vite restarts the dev server, `server.environments.ssr` is
|
|
23
|
+
* replaced — we use this reference to detect that and recreate.
|
|
24
|
+
*/
|
|
25
|
+
#ssrEnvironment;
|
|
26
|
+
/**
|
|
27
|
+
* Factory provided by the orchestrator to lazily create the runner.
|
|
28
|
+
* Indirection keeps this class decoupled from how the runner is built.
|
|
29
|
+
*/
|
|
30
|
+
#createRunner;
|
|
31
|
+
constructor(createRunner) {
|
|
32
|
+
this.#createRunner = createRunner;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Imports a module through the runner. Recreates the runner if the
|
|
36
|
+
* dev server's SSR environment was swapped underneath us.
|
|
37
|
+
*/
|
|
38
|
+
async import(server, entry, opts) {
|
|
39
|
+
const currentSsrEnv = server.environments.ssr;
|
|
40
|
+
if (this.#ssrEnvironment !== currentSsrEnv) {
|
|
41
|
+
if (this.#runner) await this.#runner.close();
|
|
42
|
+
this.#runner = void 0;
|
|
43
|
+
this.#ssrEnvironment = currentSsrEnv;
|
|
44
|
+
}
|
|
45
|
+
this.#runner ??= await this.#createRunner();
|
|
46
|
+
if (opts.fresh) this.#runner.clearCache();
|
|
47
|
+
return this.#runner.import(entry);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Closes the runner, if any. Safe to call when no runner has been
|
|
51
|
+
* created yet.
|
|
52
|
+
*/
|
|
53
|
+
async close() {
|
|
54
|
+
if (this.#runner) {
|
|
55
|
+
await this.#runner.close();
|
|
56
|
+
this.#runner = void 0;
|
|
57
|
+
this.#ssrEnvironment = void 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/server_modules/bundled_module_resolver.ts
|
|
63
|
+
/**
|
|
64
|
+
* Resolves and imports server-side modules from the production SSR build.
|
|
65
|
+
*
|
|
66
|
+
* In production there is no Vite dev server — entrypoints declared as
|
|
67
|
+
* `serverEntrypoints` are pre-built into `<buildDirectory>/server` and
|
|
68
|
+
* recorded in `<buildDirectory>/server/.vite/manifest.json`. The
|
|
69
|
+
* resolver reads that manifest to map an entry source path to the
|
|
70
|
+
* emitted bundle file, then imports it through Node's native `import()`.
|
|
71
|
+
*
|
|
72
|
+
* Imports are cached per entry so repeated calls reuse the same module
|
|
73
|
+
* instance and side-effects only run once.
|
|
74
|
+
*/
|
|
75
|
+
var BundledModuleResolver = class {
|
|
76
|
+
/**
|
|
77
|
+
* Absolute path to `<buildDirectory>/server`.
|
|
78
|
+
*/
|
|
79
|
+
#serverDir;
|
|
80
|
+
/**
|
|
81
|
+
* Cache of in-flight or resolved module imports, keyed by entry.
|
|
82
|
+
* Stores the promise so concurrent callers share the same import.
|
|
83
|
+
*/
|
|
84
|
+
#cache = /* @__PURE__ */ new Map();
|
|
85
|
+
/**
|
|
86
|
+
* Lazily-loaded manifest contents. Loaded once on first import call.
|
|
87
|
+
*/
|
|
88
|
+
#manifest;
|
|
89
|
+
constructor(buildDirectory) {
|
|
90
|
+
this.#serverDir = join(buildDirectory, "server");
|
|
91
|
+
}
|
|
92
|
+
async import(entry) {
|
|
93
|
+
let pending = this.#cache.get(entry);
|
|
94
|
+
if (!pending) {
|
|
95
|
+
const chunk = this.#readManifest()[entry];
|
|
96
|
+
if (!chunk) throw new Error(`Cannot loadServerModule("${entry}"): no chunk for this entry in the SSR manifest. Make sure the entry is declared in serverEntrypoints and the application has been rebuilt.`);
|
|
97
|
+
pending = import(pathToFileURL(join(this.#serverDir, chunk.file)).href);
|
|
98
|
+
this.#cache.set(entry, pending);
|
|
99
|
+
}
|
|
100
|
+
return pending;
|
|
101
|
+
}
|
|
102
|
+
#readManifest() {
|
|
103
|
+
if (this.#manifest) return this.#manifest;
|
|
104
|
+
const manifestPath = join(this.#serverDir, ".vite/manifest.json");
|
|
105
|
+
if (!existsSync(manifestPath)) throw new Error(`SSR manifest not found at ${manifestPath}. Build the application with at least one declared serverEntrypoint before loading server modules.`);
|
|
106
|
+
this.#manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
107
|
+
return this.#manifest;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/server_modules/server_module_loader.ts
|
|
112
|
+
/**
|
|
113
|
+
* Public entry point for loading server-side modules processed by Vite.
|
|
114
|
+
*
|
|
115
|
+
* Picks between two collaborators based on whether the Vite dev server
|
|
116
|
+
* is running:
|
|
117
|
+
*
|
|
118
|
+
* - In development, delegates to {@link DevModuleRunner} which evaluates
|
|
119
|
+
* the entry through Vite's `ModuleRunner`, with HMR-driven cache
|
|
120
|
+
* invalidation.
|
|
121
|
+
* - In production, delegates to {@link BundledModuleResolver} which
|
|
122
|
+
* imports the pre-built bundle from disk.
|
|
123
|
+
*
|
|
124
|
+
* Entry strings are passed through verbatim to mirror how client
|
|
125
|
+
* `entrypoints` are handled — the caller is responsible for using the
|
|
126
|
+
* exact string declared in `serverEntrypoints`.
|
|
127
|
+
*/
|
|
128
|
+
var ServerModuleLoader = class {
|
|
129
|
+
#getDevServer;
|
|
130
|
+
#devRunner;
|
|
131
|
+
#bundled;
|
|
132
|
+
constructor(getDevServer, buildDirectory, createRunner) {
|
|
133
|
+
this.#getDevServer = getDevServer;
|
|
134
|
+
this.#devRunner = new DevModuleRunner(createRunner);
|
|
135
|
+
this.#bundled = new BundledModuleResolver(buildDirectory);
|
|
136
|
+
}
|
|
137
|
+
async load(entry, opts = {}) {
|
|
138
|
+
const server = this.#getDevServer();
|
|
139
|
+
if (server) return this.#devRunner.import(server, entry, opts);
|
|
140
|
+
return this.#bundled.import(entry);
|
|
141
|
+
}
|
|
142
|
+
async close() {
|
|
143
|
+
await this.#devRunner.close();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
//#endregion
|
|
5
147
|
//#region src/vite.ts
|
|
6
148
|
const STYLE_FILE_REGEX = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\?)/;
|
|
7
149
|
/**
|
|
@@ -17,6 +159,11 @@ var Vite = class {
|
|
|
17
159
|
#options;
|
|
18
160
|
#devServer;
|
|
19
161
|
/**
|
|
162
|
+
* Loads server-side TypeScript modules through Vite. Picks between
|
|
163
|
+
* the dev `ModuleRunner` and the production SSR bundle automatically.
|
|
164
|
+
*/
|
|
165
|
+
#serverModuleLoader;
|
|
166
|
+
/**
|
|
20
167
|
* Indicates whether the Vite manifest file exists on disk
|
|
21
168
|
*/
|
|
22
169
|
hasManifestFile;
|
|
@@ -39,6 +186,7 @@ var Vite = class {
|
|
|
39
186
|
this.#options = options;
|
|
40
187
|
this.#options.assetsUrl = (this.#options.assetsUrl || "/").replace(/\/$/, "");
|
|
41
188
|
this.hasManifestFile = existsSync(this.#options.manifestFile);
|
|
189
|
+
this.#serverModuleLoader = new ServerModuleLoader(() => this.#devServer, this.#options.buildDirectory, () => this.createModuleRunner());
|
|
42
190
|
}
|
|
43
191
|
/**
|
|
44
192
|
* Reads the file contents as JSON
|
|
@@ -168,11 +316,17 @@ var Vite = class {
|
|
|
168
316
|
const tags = entryPoints.map((entrypoint) => this.#generateTag(entrypoint, attributes));
|
|
169
317
|
const jsEntrypoints = entryPoints.filter((entrypoint) => !this.#isCssPath(entrypoint));
|
|
170
318
|
/**
|
|
171
|
-
* If the module graph is empty, that means we didn't execute the
|
|
172
|
-
* yet : we just started the AdonisJS dev server.
|
|
173
|
-
*
|
|
319
|
+
* If the client module graph is empty, that means we didn't execute the
|
|
320
|
+
* entrypoint yet : we just started the AdonisJS dev server. So let's
|
|
321
|
+
* execute the entrypoints to populate the client module graph.
|
|
322
|
+
*
|
|
323
|
+
* Use the per-environment client graph instead of the backward-compat
|
|
324
|
+
* `server.moduleGraph` union (client + ssr). Otherwise an SSR runner
|
|
325
|
+
* (e.g. @adonisjs/inertia rendering before @vite()) populates the ssr
|
|
326
|
+
* graph, the union check returns non-empty, the client warmup is
|
|
327
|
+
* skipped, and no <link rel="stylesheet"> tags are emitted.
|
|
174
328
|
*/
|
|
175
|
-
if (server?.moduleGraph.idToModuleMap.size === 0) await Promise.allSettled(jsEntrypoints.map((entrypoint) => server.warmupRequest(`/${entrypoint}`)));
|
|
329
|
+
if (server?.environments.client.moduleGraph.idToModuleMap.size === 0) await Promise.allSettled(jsEntrypoints.map((entrypoint) => server.warmupRequest(`/${entrypoint}`)));
|
|
176
330
|
/**
|
|
177
331
|
* We need to collect the CSS files imported by the entrypoints
|
|
178
332
|
* Otherwise, we gonna have a FOUC each time we full reload the page
|
|
@@ -186,7 +340,7 @@ var Vite = class {
|
|
|
186
340
|
*/
|
|
187
341
|
for (const entryPoint of jsEntrypoints) {
|
|
188
342
|
const filePath = join(server.config.root, entryPoint);
|
|
189
|
-
const entryMod = server.moduleGraph.getModuleById(string.toUnixSlash(filePath));
|
|
343
|
+
const entryMod = server.environments.client.moduleGraph.getModuleById(string.toUnixSlash(filePath));
|
|
190
344
|
if (entryMod) this.#collectCss(entryMod, preloadUrls, visitedModules);
|
|
191
345
|
}
|
|
192
346
|
Array.from(preloadUrls).map((href) => this.#generateElement({
|
|
@@ -408,6 +562,9 @@ var Vite = class {
|
|
|
408
562
|
const { createServerModuleRunner } = await import("vite");
|
|
409
563
|
return createServerModuleRunner(this.#devServer.environments.ssr, options);
|
|
410
564
|
}
|
|
565
|
+
loadServerModule(entry, opts) {
|
|
566
|
+
return this.#serverModuleLoader.load(entry, opts);
|
|
567
|
+
}
|
|
411
568
|
/**
|
|
412
569
|
* Gracefully stops the Vite development server
|
|
413
570
|
*
|
|
@@ -417,6 +574,7 @@ var Vite = class {
|
|
|
417
574
|
* await vite.stopDevServer()
|
|
418
575
|
*/
|
|
419
576
|
async stopDevServer() {
|
|
577
|
+
await this.#serverModuleLoader.close();
|
|
420
578
|
await this.#devServer?.close();
|
|
421
579
|
}
|
|
422
580
|
/**
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* AdonisJS server.
|
|
11
11
|
*/
|
|
12
12
|
var ViteMiddleware = class {
|
|
13
|
+
#devServer;
|
|
13
14
|
/**
|
|
14
15
|
* Creates a new ViteMiddleware instance
|
|
15
16
|
*
|
|
@@ -20,6 +21,7 @@ var ViteMiddleware = class {
|
|
|
20
21
|
*/
|
|
21
22
|
constructor(vite) {
|
|
22
23
|
this.vite = vite;
|
|
24
|
+
this.#devServer = this.vite.getDevServer();
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Handles HTTP requests by proxying them to the Vite dev server when appropriate
|
|
@@ -32,8 +34,7 @@ var ViteMiddleware = class {
|
|
|
32
34
|
* await middleware.handle(ctx, next)
|
|
33
35
|
*/
|
|
34
36
|
async handle({ request, response }, next) {
|
|
35
|
-
|
|
36
|
-
if (!devServer) return next();
|
|
37
|
+
if (!this.#devServer) return next();
|
|
37
38
|
return new Promise((resolve, reject) => {
|
|
38
39
|
function done(error) {
|
|
39
40
|
response.response.removeListener("finish", done);
|
|
@@ -50,7 +51,7 @@ var ViteMiddleware = class {
|
|
|
50
51
|
* to Node.js.
|
|
51
52
|
*/
|
|
52
53
|
response.relayHeaders();
|
|
53
|
-
devServer.middlewares.handle(request.request, response.response, async () => {
|
|
54
|
+
this.#devServer.middlewares.handle(request.request, response.response, async () => {
|
|
54
55
|
/**
|
|
55
56
|
* This callback is invoked when Vite does not handle the request. In that
|
|
56
57
|
* case, we will call next and resolve this promise. Also we remove the
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/vite",
|
|
3
3
|
"description": "Vite plugin for AdonisJS",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.0-next.1",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"docs": "typedoc"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@adonisjs/assembler": "^8.
|
|
48
|
-
"@adonisjs/core": "^7.
|
|
47
|
+
"@adonisjs/assembler": "^8.4.0",
|
|
48
|
+
"@adonisjs/core": "^7.3.2",
|
|
49
49
|
"@adonisjs/eslint-config": "^3.0.0",
|
|
50
50
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
51
|
-
"@adonisjs/session": "^8.
|
|
51
|
+
"@adonisjs/session": "^8.1.0",
|
|
52
52
|
"@adonisjs/shield": "^9.0.0",
|
|
53
53
|
"@adonisjs/tsconfig": "^2.0.0",
|
|
54
54
|
"@japa/assert": "4.2.0",
|
|
@@ -56,34 +56,35 @@
|
|
|
56
56
|
"@japa/runner": "5.3.0",
|
|
57
57
|
"@japa/snapshot": "^2.0.10",
|
|
58
58
|
"@poppinss/ts-exec": "^1.4.4",
|
|
59
|
-
"@release-it/conventional-changelog": "^
|
|
60
|
-
"@types/node": "^25.
|
|
61
|
-
"@types/
|
|
59
|
+
"@release-it/conventional-changelog": "^11.0.0",
|
|
60
|
+
"@types/node": "^25.6.0",
|
|
61
|
+
"@types/picomatch": "^4.0.3",
|
|
62
|
+
"@types/supertest": "^7.2.0",
|
|
62
63
|
"c8": "^11.0.0",
|
|
63
64
|
"copyfiles": "^2.4.1",
|
|
64
65
|
"cross-env": "^10.1.0",
|
|
65
66
|
"del-cli": "^7.0.0",
|
|
66
67
|
"edge.js": "^6.5.0",
|
|
67
|
-
"eslint": "^10.0
|
|
68
|
-
"prettier": "^3.8.
|
|
69
|
-
"release-it": "^
|
|
68
|
+
"eslint": "^10.3.0",
|
|
69
|
+
"prettier": "^3.8.3",
|
|
70
|
+
"release-it": "^20.0.1",
|
|
70
71
|
"supertest": "^7.2.2",
|
|
71
|
-
"tsdown": "^0.21.
|
|
72
|
-
"typedoc": "^0.28.
|
|
73
|
-
"typescript": "~
|
|
74
|
-
"vite": "^
|
|
72
|
+
"tsdown": "^0.21.10",
|
|
73
|
+
"typedoc": "^0.28.19",
|
|
74
|
+
"typescript": "~6.0.3",
|
|
75
|
+
"vite": "^8.0.10"
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
|
-
"@poppinss/utils": "^7.0.
|
|
78
|
+
"@poppinss/utils": "^7.0.1",
|
|
78
79
|
"edge-error": "^4.0.2",
|
|
79
|
-
"
|
|
80
|
+
"picomatch": "^4.0.4"
|
|
80
81
|
},
|
|
81
82
|
"peerDependencies": {
|
|
82
83
|
"@adonisjs/assembler": "^8.0.0-next.10 || ^8.0.0",
|
|
83
84
|
"@adonisjs/core": "^7.0.0-next.3 || ^7.0.0",
|
|
84
85
|
"@adonisjs/shield": "^9.0.0-next.0 || ^9.0.0",
|
|
85
86
|
"edge.js": "^6.0.1",
|
|
86
|
-
"vite": "^
|
|
87
|
+
"vite": "^8.0.0"
|
|
87
88
|
},
|
|
88
89
|
"peerDependenciesMeta": {
|
|
89
90
|
"edge.js": {
|