@adonisjs/vite 3.0.0-10 → 3.0.0-11
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-MQRASPMO.js → chunk-G4LGE4JY.js} +7 -3
- package/build/chunk-G4LGE4JY.js.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/providers/vite_provider.js +5 -9
- package/build/providers/vite_provider.js.map +1 -1
- package/build/src/client/main.js +6 -0
- package/build/src/client/main.js.map +1 -1
- package/build/src/{middleware/vite_middleware.d.ts → vite_middleware.d.ts} +2 -2
- package/build/src/vite_middleware.js +7 -0
- package/package.json +5 -1
- package/build/chunk-MQRASPMO.js.map +0 -1
- package/build/vite_middleware-AQXJUYMB.js +0 -7
- /package/build/{vite_middleware-AQXJUYMB.js.map → src/vite_middleware.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/vite_middleware.ts
|
|
2
2
|
var ViteMiddleware = class {
|
|
3
3
|
constructor(vite) {
|
|
4
4
|
this.vite = vite;
|
|
@@ -6,7 +6,11 @@ var ViteMiddleware = class {
|
|
|
6
6
|
}
|
|
7
7
|
#devServer;
|
|
8
8
|
async handle({ request, response }, next) {
|
|
9
|
-
|
|
9
|
+
if (!this.#devServer)
|
|
10
|
+
return next();
|
|
11
|
+
if (this.#devServer.config.server.cors === false)
|
|
12
|
+
response.relayHeaders();
|
|
13
|
+
await new Promise((resolve) => {
|
|
10
14
|
this.#devServer.middlewares.handle(request.request, response.response, () => {
|
|
11
15
|
return resolve(next());
|
|
12
16
|
});
|
|
@@ -17,4 +21,4 @@ var ViteMiddleware = class {
|
|
|
17
21
|
export {
|
|
18
22
|
ViteMiddleware
|
|
19
23
|
};
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-G4LGE4JY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite_middleware.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ViteDevServer } from 'vite'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\n\nimport type { Vite } from './vite.js'\n\n/**\n * Since Vite dev server is integrated within the AdonisJS process, this\n * middleware is used to proxy the requests to it.\n *\n * Some of the requests are directly handled by the Vite dev server,\n * like the one for the assets, while others are passed down to the\n * AdonisJS server.\n */\nexport default class ViteMiddleware {\n #devServer: ViteDevServer\n\n constructor(protected vite: Vite) {\n this.#devServer = this.vite.getDevServer()!\n }\n\n async handle({ request, response }: HttpContext, next: NextFn) {\n if (!this.#devServer) return next()\n\n /**\n * @adonisjs/cors should handle the CORS instead of Vite\n */\n if (this.#devServer.config.server.cors === false) response.relayHeaders()\n\n /**\n * Proxy the request to the vite dev server\n */\n await new Promise((resolve) => {\n this.#devServer.middlewares.handle(request.request, response.response, () => {\n return resolve(next())\n })\n })\n }\n}\n"],"mappings":";AAuBA,IAAqB,iBAArB,MAAoC;AAAA,EAGlC,YAAsB,MAAY;AAAZ;AACpB,SAAK,aAAa,KAAK,KAAK,aAAa;AAAA,EAC3C;AAAA,EAJA;AAAA,EAMA,MAAM,OAAO,EAAE,SAAS,SAAS,GAAgB,MAAc;AAC7D,QAAI,CAAC,KAAK;AAAY,aAAO,KAAK;AAKlC,QAAI,KAAK,WAAW,OAAO,OAAO,SAAS;AAAO,eAAS,aAAa;AAKxE,UAAM,IAAI,QAAQ,CAAC,YAAY;AAC7B,WAAK,WAAW,YAAY,OAAO,QAAQ,SAAS,SAAS,UAAU,MAAM;AAC3E,eAAO,QAAQ,KAAK,CAAC;AAAA,MACvB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/build/index.js
CHANGED
|
@@ -18,6 +18,9 @@ async function configure(command) {
|
|
|
18
18
|
rcFile.addProvider("@adonisjs/vite/vite_provider");
|
|
19
19
|
rcFile.addMetaFile("public/**", false);
|
|
20
20
|
});
|
|
21
|
+
await codemods.registerMiddleware("server", [
|
|
22
|
+
{ path: "@adonisjs/vite/vite_middleware", position: "after" }
|
|
23
|
+
]);
|
|
21
24
|
if (shouldInstallPackages === void 0) {
|
|
22
25
|
shouldInstallPackages = await command.prompt.confirm('Do you want to install "vite"?');
|
|
23
26
|
}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../stubs/main.ts","../configure.ts","../src/define_config.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { getDirname } from '@poppinss/utils'\nexport const stubsRoot = getDirname(import.meta.url)\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\n\nimport { stubsRoot } from './stubs/main.js'\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n const codemods = await command.createCodemods()\n let shouldInstallPackages: boolean | undefined = command.parsedFlags.install\n\n /**\n * Publish stubs\n */\n await codemods.makeUsingStub(stubsRoot, 'config/vite.stub', {})\n await codemods.makeUsingStub(stubsRoot, 'vite.config.stub', {})\n await codemods.makeUsingStub(stubsRoot, 'js_entrypoint.stub', {})\n\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/vite/vite_provider')\n rcFile.addMetaFile('public/**', false)\n })\n\n /**\n * Prompt when `install` or `--no-install` flags are\n * not used\n */\n if (shouldInstallPackages === undefined) {\n shouldInstallPackages = await command.prompt.confirm('Do you want to install \"vite\"?')\n }\n\n /**\n * Install dependency or list the command to install it\n */\n if (shouldInstallPackages) {\n await codemods.installPackages([{ name: 'vite', isDevDependency: true }])\n } else {\n await codemods.listPackagesToInstall([{ name: 'vite', isDevDependency: true }])\n }\n}\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\n\nimport type { ViteOptions } from './types.js'\n\n/**\n * Define the backend config for Vite\n */\nexport function defineConfig(config: Partial<ViteOptions>): ViteOptions {\n return {\n buildDirectory: 'public/assets',\n assetsUrl: '/assets',\n manifestFile: config.buildDirectory\n ? join(config.buildDirectory, '.vite/manifest.json')\n : 'public/assets/.vite/manifest.json',\n ...config,\n }\n}\n"],"mappings":";;;;;;AASA,SAAS,kBAAkB;AACpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACMnD,eAAsB,UAAU,SAAoB;AAClD,QAAM,WAAW,MAAM,QAAQ,eAAe;AAC9C,MAAI,wBAA6C,QAAQ,YAAY;AAKrE,QAAM,SAAS,cAAc,WAAW,oBAAoB,CAAC,CAAC;AAC9D,QAAM,SAAS,cAAc,WAAW,oBAAoB,CAAC,CAAC;AAC9D,QAAM,SAAS,cAAc,WAAW,sBAAsB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"sources":["../stubs/main.ts","../configure.ts","../src/define_config.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { getDirname } from '@poppinss/utils'\nexport const stubsRoot = getDirname(import.meta.url)\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\n\nimport { stubsRoot } from './stubs/main.js'\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n const codemods = await command.createCodemods()\n let shouldInstallPackages: boolean | undefined = command.parsedFlags.install\n\n /**\n * Publish stubs\n */\n await codemods.makeUsingStub(stubsRoot, 'config/vite.stub', {})\n await codemods.makeUsingStub(stubsRoot, 'vite.config.stub', {})\n await codemods.makeUsingStub(stubsRoot, 'js_entrypoint.stub', {})\n\n /**\n * Update RC file\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/vite/vite_provider')\n rcFile.addMetaFile('public/**', false)\n })\n\n /**\n * Add server middleware\n */\n await codemods.registerMiddleware('server', [\n { path: '@adonisjs/vite/vite_middleware', position: 'after' },\n ])\n\n /**\n * Prompt when `install` or `--no-install` flags are\n * not used\n */\n if (shouldInstallPackages === undefined) {\n shouldInstallPackages = await command.prompt.confirm('Do you want to install \"vite\"?')\n }\n\n /**\n * Install dependency or list the command to install it\n */\n if (shouldInstallPackages) {\n await codemods.installPackages([{ name: 'vite', isDevDependency: true }])\n } else {\n await codemods.listPackagesToInstall([{ name: 'vite', isDevDependency: true }])\n }\n}\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\n\nimport type { ViteOptions } from './types.js'\n\n/**\n * Define the backend config for Vite\n */\nexport function defineConfig(config: Partial<ViteOptions>): ViteOptions {\n return {\n buildDirectory: 'public/assets',\n assetsUrl: '/assets',\n manifestFile: config.buildDirectory\n ? join(config.buildDirectory, '.vite/manifest.json')\n : 'public/assets/.vite/manifest.json',\n ...config,\n }\n}\n"],"mappings":";;;;;;AASA,SAAS,kBAAkB;AACpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACMnD,eAAsB,UAAU,SAAoB;AAClD,QAAM,WAAW,MAAM,QAAQ,eAAe;AAC9C,MAAI,wBAA6C,QAAQ,YAAY;AAKrE,QAAM,SAAS,cAAc,WAAW,oBAAoB,CAAC,CAAC;AAC9D,QAAM,SAAS,cAAc,WAAW,oBAAoB,CAAC,CAAC;AAC9D,QAAM,SAAS,cAAc,WAAW,sBAAsB,CAAC,CAAC;AAKhE,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,YAAY,8BAA8B;AACjD,WAAO,YAAY,aAAa,KAAK;AAAA,EACvC,CAAC;AAKD,QAAM,SAAS,mBAAmB,UAAU;AAAA,IAC1C,EAAE,MAAM,kCAAkC,UAAU,QAAQ;AAAA,EAC9D,CAAC;AAMD,MAAI,0BAA0B,QAAW;AACvC,4BAAwB,MAAM,QAAQ,OAAO,QAAQ,gCAAgC;AAAA,EACvF;AAKA,MAAI,uBAAuB;AACzB,UAAM,SAAS,gBAAgB,CAAC,EAAE,MAAM,QAAQ,iBAAiB,KAAK,CAAC,CAAC;AAAA,EAC1E,OAAO;AACL,UAAM,SAAS,sBAAsB,CAAC,EAAE,MAAM,QAAQ,iBAAiB,KAAK,CAAC,CAAC;AAAA,EAChF;AACF;;;ACjDA,SAAS,YAAY;AAOd,SAAS,aAAa,QAA2C;AACtE,SAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX,cAAc,OAAO,iBACjB,KAAK,OAAO,gBAAgB,qBAAqB,IACjD;AAAA,IACJ,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ViteMiddleware
|
|
3
|
+
} from "../chunk-G4LGE4JY.js";
|
|
1
4
|
import {
|
|
2
5
|
Vite
|
|
3
6
|
} from "../chunk-W6CJOSLQ.js";
|
|
4
7
|
import "../chunk-CFRBPZ4N.js";
|
|
5
|
-
import {
|
|
6
|
-
ViteMiddleware
|
|
7
|
-
} from "../chunk-MQRASPMO.js";
|
|
8
8
|
|
|
9
9
|
// providers/vite_provider.ts
|
|
10
10
|
var ViteProvider = class {
|
|
@@ -53,7 +53,7 @@ var ViteProvider = class {
|
|
|
53
53
|
const config = this.app.config.get("vite");
|
|
54
54
|
const vite = new Vite(this.#shouldRunVite, config);
|
|
55
55
|
this.app.container.bind("vite", () => vite);
|
|
56
|
-
this.app.container.
|
|
56
|
+
this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite));
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* - Register edge tags
|
|
@@ -63,12 +63,8 @@ var ViteProvider = class {
|
|
|
63
63
|
await this.registerEdgePlugin();
|
|
64
64
|
if (!this.#shouldRunVite)
|
|
65
65
|
return;
|
|
66
|
-
const
|
|
67
|
-
this.app.container.make("vite"),
|
|
68
|
-
this.app.container.make("server")
|
|
69
|
-
]);
|
|
66
|
+
const vite = await this.app.container.make("vite");
|
|
70
67
|
await vite.createDevServer();
|
|
71
|
-
server.use([() => import("../vite_middleware-AQXJUYMB.js")]);
|
|
72
68
|
}
|
|
73
69
|
/**
|
|
74
70
|
* Stop Vite server when running in development or test
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../providers/vite_provider.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ApplicationService } from '@adonisjs/core/types'\nimport type { cspKeywords as ShieldCSPKeywords } from '@adonisjs/shield'\n\nimport { Vite } from '../src/vite.js'\nimport type { ViteOptions } from '../src/types.js'\nimport ViteMiddleware from '../src/
|
|
1
|
+
{"version":3,"sources":["../../providers/vite_provider.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ApplicationService } from '@adonisjs/core/types'\nimport type { cspKeywords as ShieldCSPKeywords } from '@adonisjs/shield'\n\nimport { Vite } from '../src/vite.js'\nimport type { ViteOptions } from '../src/types.js'\nimport ViteMiddleware from '../src/vite_middleware.js'\n\ndeclare module '@adonisjs/core/types' {\n interface ContainerBindings {\n vite: Vite\n }\n}\n\nexport default class ViteProvider {\n #shouldRunVite: boolean\n\n constructor(protected app: ApplicationService) {\n /**\n * We should only run Vite in development and test environments\n */\n const env = this.app.getEnvironment()\n this.#shouldRunVite = (this.app.inDev || this.app.inTest) && (env === 'web' || env === 'test')\n }\n\n /**\n * Registers edge plugin when edge is installed\n */\n protected async registerEdgePlugin() {\n if (this.app.usingEdgeJS) {\n const edge = await import('edge.js')\n const vite = await this.app.container.make('vite')\n const { edgePluginVite } = await import('../src/plugins/edge.js')\n edge.default.use(edgePluginVite(vite))\n }\n }\n\n /**\n * Registers CSP keywords when @adonisjs/shield is installed\n */\n protected async registerShieldKeywords() {\n let cspKeywords: typeof ShieldCSPKeywords | null = null\n try {\n const shieldExports = await import('@adonisjs/shield')\n cspKeywords = shieldExports.cspKeywords\n } catch {}\n\n if (!cspKeywords) return\n\n const vite = await this.app.container.make('vite')\n\n /**\n * Registering the @viteUrl keyword for CSP directives.\n * Returns http URL to the dev or the CDN server, otherwise\n * an empty string\n */\n cspKeywords.register('@viteUrl', function () {\n const assetsURL = vite.assetsUrl()\n if (!assetsURL || !assetsURL.startsWith('http://') || assetsURL.startsWith('https://')) {\n return ''\n }\n\n return assetsURL\n })\n }\n\n /**\n * Register Vite bindings\n */\n register() {\n const config = this.app.config.get<ViteOptions>('vite')\n\n const vite = new Vite(this.#shouldRunVite, config)\n this.app.container.bind('vite', () => vite)\n this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite))\n }\n\n /**\n * - Register edge tags\n * - Start Vite server when running in development or test\n */\n async boot() {\n await this.registerEdgePlugin()\n\n if (!this.#shouldRunVite) return\n\n const vite = await this.app.container.make('vite')\n await vite.createDevServer()\n }\n\n /**\n * Stop Vite server when running in development or test\n */\n async shutdown() {\n if (!this.#shouldRunVite) return\n\n const vite = await this.app.container.make('vite')\n await vite.stopDevServer()\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,IAAqB,eAArB,MAAkC;AAAA,EAGhC,YAAsB,KAAyB;AAAzB;AAIpB,UAAM,MAAM,KAAK,IAAI,eAAe;AACpC,SAAK,kBAAkB,KAAK,IAAI,SAAS,KAAK,IAAI,YAAY,QAAQ,SAAS,QAAQ;AAAA,EACzF;AAAA,EARA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAgB,qBAAqB;AACnC,QAAI,KAAK,IAAI,aAAa;AACxB,YAAM,OAAO,MAAM,OAAO,SAAS;AACnC,YAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,YAAM,EAAE,eAAe,IAAI,MAAM,OAAO,wBAAwB;AAChE,WAAK,QAAQ,IAAI,eAAe,IAAI,CAAC;AAAA,IACvC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,yBAAyB;AACvC,QAAI,cAA+C;AACnD,QAAI;AACF,YAAM,gBAAgB,MAAM,OAAO,kBAAkB;AACrD,oBAAc,cAAc;AAAA,IAC9B,QAAQ;AAAA,IAAC;AAET,QAAI,CAAC;AAAa;AAElB,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AAOjD,gBAAY,SAAS,YAAY,WAAY;AAC3C,YAAM,YAAY,KAAK,UAAU;AACjC,UAAI,CAAC,aAAa,CAAC,UAAU,WAAW,SAAS,KAAK,UAAU,WAAW,UAAU,GAAG;AACtF,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACT,UAAM,SAAS,KAAK,IAAI,OAAO,IAAiB,MAAM;AAEtD,UAAM,OAAO,IAAI,KAAK,KAAK,gBAAgB,MAAM;AACjD,SAAK,IAAI,UAAU,KAAK,QAAQ,MAAM,IAAI;AAC1C,SAAK,IAAI,UAAU,UAAU,gBAAgB,MAAM,IAAI,eAAe,IAAI,CAAC;AAAA,EAC7E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO;AACX,UAAM,KAAK,mBAAmB;AAE9B,QAAI,CAAC,KAAK;AAAgB;AAE1B,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,UAAM,KAAK,gBAAgB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW;AACf,QAAI,CAAC,KAAK;AAAgB;AAE1B,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,UAAM,KAAK,cAAc;AAAA,EAC3B;AACF;","names":[]}
|
package/build/src/client/main.js
CHANGED
|
@@ -19,6 +19,12 @@ function configHook(options, userConfig, { command }) {
|
|
|
19
19
|
const config2 = {
|
|
20
20
|
publicDir: userConfig.publicDir ?? false,
|
|
21
21
|
base: resolveBase(userConfig, options, command),
|
|
22
|
+
/**
|
|
23
|
+
* Disable the vite dev server cors handling. Otherwise, it will
|
|
24
|
+
* override the cors settings defined by @adonisjs/cors
|
|
25
|
+
* https://github.com/adonisjs/vite/issues/13
|
|
26
|
+
*/
|
|
27
|
+
server: { cors: userConfig.server?.cors ?? false },
|
|
22
28
|
build: {
|
|
23
29
|
assetsDir: "",
|
|
24
30
|
emptyOutDir: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/main.ts","../../../src/client/config.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference types=\"@vavite/multibuild\" />\n\nimport { PluginOption } from 'vite'\nimport PluginRestart from 'vite-plugin-restart'\n\nimport { config } from './config.js'\nimport type { PluginOptions } from './types.js'\n\ndeclare module 'vite' {\n interface ManifestChunk {\n integrity: string\n }\n}\n\n/**\n * Vite plugin for AdonisJS\n */\nexport default function adonisjs(options: PluginOptions): PluginOption[] {\n const fullOptions = Object.assign(\n {\n assetsUrl: '/assets',\n buildDirectory: 'public/assets',\n reload: ['./resources/views/**/*.edge'],\n },\n options\n )\n\n return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)]\n}\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport type { ConfigEnv, Plugin, UserConfig } from 'vite'\n\nimport { addTrailingSlash } from '../utils.js'\nimport type { PluginFullOptions } from './types.js'\n\n/**\n * Resolve the `config.base` value\n */\nexport function resolveBase(\n config: UserConfig,\n options: PluginFullOptions,\n command: 'build' | 'serve'\n): string {\n if (config.base) return config.base\n if (command === 'build') {\n return addTrailingSlash(options.assetsUrl)\n }\n\n return '/'\n}\n\n/**\n * Vite config hook\n */\nexport function configHook(\n options: PluginFullOptions,\n userConfig: UserConfig,\n { command }: ConfigEnv\n): UserConfig {\n const config: UserConfig = {\n publicDir: userConfig.publicDir ?? false,\n base: resolveBase(userConfig, options, command),\n\n build: {\n assetsDir: '',\n emptyOutDir: true,\n manifest: userConfig.build?.manifest ?? true,\n outDir: userConfig.build?.outDir ?? options.buildDirectory,\n assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,\n\n rollupOptions: {\n input: options.entrypoints.map((entrypoint) => join(userConfig.root || '', entrypoint)),\n },\n },\n }\n\n return config\n}\n\n/**\n * Update the user vite config to match the Adonis requirements\n */\nexport const config = (options: PluginFullOptions): Plugin => {\n return {\n name: 'vite-plugin-adonis:config',\n enforce: 'post',\n config: configHook.bind(null, options),\n }\n}\n"],"mappings":";;;;;AAYA,OAAO,mBAAmB;;;ACH1B,SAAS,YAAY;AASd,SAAS,YACdA,SACA,SACA,SACQ;AACR,MAAIA,QAAO;AAAM,WAAOA,QAAO;AAC/B,MAAI,YAAY,SAAS;AACvB,WAAO,iBAAiB,QAAQ,SAAS;AAAA,EAC3C;AAEA,SAAO;AACT;AAKO,SAAS,WACd,SACA,YACA,EAAE,QAAQ,GACE;AACZ,QAAMA,UAAqB;AAAA,IACzB,WAAW,WAAW,aAAa;AAAA,IACnC,MAAM,YAAY,YAAY,SAAS,OAAO;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/main.ts","../../../src/client/config.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference types=\"@vavite/multibuild\" />\n\nimport { PluginOption } from 'vite'\nimport PluginRestart from 'vite-plugin-restart'\n\nimport { config } from './config.js'\nimport type { PluginOptions } from './types.js'\n\ndeclare module 'vite' {\n interface ManifestChunk {\n integrity: string\n }\n}\n\n/**\n * Vite plugin for AdonisJS\n */\nexport default function adonisjs(options: PluginOptions): PluginOption[] {\n const fullOptions = Object.assign(\n {\n assetsUrl: '/assets',\n buildDirectory: 'public/assets',\n reload: ['./resources/views/**/*.edge'],\n },\n options\n )\n\n return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)]\n}\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport type { ConfigEnv, Plugin, UserConfig } from 'vite'\n\nimport { addTrailingSlash } from '../utils.js'\nimport type { PluginFullOptions } from './types.js'\n\n/**\n * Resolve the `config.base` value\n */\nexport function resolveBase(\n config: UserConfig,\n options: PluginFullOptions,\n command: 'build' | 'serve'\n): string {\n if (config.base) return config.base\n if (command === 'build') {\n return addTrailingSlash(options.assetsUrl)\n }\n\n return '/'\n}\n\n/**\n * Vite config hook\n */\nexport function configHook(\n options: PluginFullOptions,\n userConfig: UserConfig,\n { command }: ConfigEnv\n): UserConfig {\n const config: UserConfig = {\n publicDir: userConfig.publicDir ?? false,\n base: resolveBase(userConfig, options, command),\n\n /**\n * Disable the vite dev server cors handling. Otherwise, it will\n * override the cors settings defined by @adonisjs/cors\n * https://github.com/adonisjs/vite/issues/13\n */\n server: { cors: userConfig.server?.cors ?? false },\n\n build: {\n assetsDir: '',\n emptyOutDir: true,\n manifest: userConfig.build?.manifest ?? true,\n outDir: userConfig.build?.outDir ?? options.buildDirectory,\n assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,\n\n rollupOptions: {\n input: options.entrypoints.map((entrypoint) => join(userConfig.root || '', entrypoint)),\n },\n },\n }\n\n return config\n}\n\n/**\n * Update the user vite config to match the Adonis requirements\n */\nexport const config = (options: PluginFullOptions): Plugin => {\n return {\n name: 'vite-plugin-adonis:config',\n enforce: 'post',\n config: configHook.bind(null, options),\n }\n}\n"],"mappings":";;;;;AAYA,OAAO,mBAAmB;;;ACH1B,SAAS,YAAY;AASd,SAAS,YACdA,SACA,SACA,SACQ;AACR,MAAIA,QAAO;AAAM,WAAOA,QAAO;AAC/B,MAAI,YAAY,SAAS;AACvB,WAAO,iBAAiB,QAAQ,SAAS;AAAA,EAC3C;AAEA,SAAO;AACT;AAKO,SAAS,WACd,SACA,YACA,EAAE,QAAQ,GACE;AACZ,QAAMA,UAAqB;AAAA,IACzB,WAAW,WAAW,aAAa;AAAA,IACnC,MAAM,YAAY,YAAY,SAAS,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO9C,QAAQ,EAAE,MAAM,WAAW,QAAQ,QAAQ,MAAM;AAAA,IAEjD,OAAO;AAAA,MACL,WAAW;AAAA,MACX,aAAa;AAAA,MACb,UAAU,WAAW,OAAO,YAAY;AAAA,MACxC,QAAQ,WAAW,OAAO,UAAU,QAAQ;AAAA,MAC5C,mBAAmB,WAAW,OAAO,qBAAqB;AAAA,MAE1D,eAAe;AAAA,QACb,OAAO,QAAQ,YAAY,IAAI,CAAC,eAAe,KAAK,WAAW,QAAQ,IAAI,UAAU,CAAC;AAAA,MACxF;AAAA,IACF;AAAA,EACF;AAEA,SAAOA;AACT;AAKO,IAAM,SAAS,CAAC,YAAuC;AAC5D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ,WAAW,KAAK,MAAM,OAAO;AAAA,EACvC;AACF;;;ADjDe,SAAR,SAA0B,SAAwC;AACvE,QAAM,cAAc,OAAO;AAAA,IACzB;AAAA,MACE,WAAW;AAAA,MACX,gBAAgB;AAAA,MAChB,QAAQ,CAAC,6BAA6B;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,CAAC,cAAc,EAAE,QAAQ,YAAY,OAAO,CAAC,GAAG,OAAO,WAAW,CAAC;AAC5E;","names":["config"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { NextFn } from '@adonisjs/core/types/http';
|
|
3
|
-
import type { Vite } from '
|
|
3
|
+
import type { Vite } from './vite.js';
|
|
4
4
|
/**
|
|
5
5
|
* Since Vite dev server is integrated within the AdonisJS process, this
|
|
6
6
|
* middleware is used to proxy the requests to it.
|
|
@@ -13,5 +13,5 @@ export default class ViteMiddleware {
|
|
|
13
13
|
#private;
|
|
14
14
|
protected vite: Vite;
|
|
15
15
|
constructor(vite: Vite);
|
|
16
|
-
handle({ request, response }: HttpContext, next: NextFn): Promise<
|
|
16
|
+
handle({ request, response }: HttpContext, next: NextFn): Promise<any>;
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/vite",
|
|
3
3
|
"description": "Vite plugin for AdonisJS",
|
|
4
|
-
"version": "3.0.0-
|
|
4
|
+
"version": "3.0.0-11",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.6.0"
|
|
7
7
|
},
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
".": "./build/index.js",
|
|
18
18
|
"./vite_provider": "./build/providers/vite_provider.js",
|
|
19
19
|
"./plugins/edge": "./build/src/plugins/edge.js",
|
|
20
|
+
"./vite_middleware": "./build/src/vite_middleware.js",
|
|
20
21
|
"./build_hook": "./build/src/hooks/build_hook.js",
|
|
21
22
|
"./services/main": "./build/services/vite.js",
|
|
22
23
|
"./client": "./build/src/client/main.js",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"@japa/snapshot": "^2.0.4",
|
|
53
54
|
"@swc/core": "^1.4.2",
|
|
54
55
|
"@types/node": "^20.11.20",
|
|
56
|
+
"@types/supertest": "^6.0.2",
|
|
55
57
|
"c8": "^9.1.0",
|
|
56
58
|
"copyfiles": "^2.4.1",
|
|
57
59
|
"del-cli": "^5.1.0",
|
|
@@ -59,6 +61,7 @@
|
|
|
59
61
|
"eslint": "^8.57.0",
|
|
60
62
|
"np": "^10.0.0",
|
|
61
63
|
"prettier": "^3.2.5",
|
|
64
|
+
"supertest": "^6.3.4",
|
|
62
65
|
"ts-node": "^10.9.2",
|
|
63
66
|
"tsup": "^8.0.2",
|
|
64
67
|
"typescript": "~5.3.3",
|
|
@@ -126,6 +129,7 @@
|
|
|
126
129
|
"entry": [
|
|
127
130
|
"./src/hooks/build_hook.ts",
|
|
128
131
|
"./providers/vite_provider.ts",
|
|
132
|
+
"./src/vite_middleware.ts",
|
|
129
133
|
"./src/plugins/edge.ts",
|
|
130
134
|
"./src/client/main.ts",
|
|
131
135
|
"./services/vite.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/middleware/vite_middleware.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ViteDevServer } from 'vite'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\n\nimport type { Vite } from '../vite.js'\n\n/**\n * Since Vite dev server is integrated within the AdonisJS process, this\n * middleware is used to proxy the requests to it.\n *\n * Some of the requests are directly handled by the Vite dev server,\n * like the one for the assets, while others are passed down to the\n * AdonisJS server.\n */\nexport default class ViteMiddleware {\n #devServer: ViteDevServer\n\n constructor(protected vite: Vite) {\n this.#devServer = this.vite.getDevServer()!\n }\n\n async handle({ request, response }: HttpContext, next: NextFn) {\n return await new Promise((resolve) => {\n this.#devServer.middlewares.handle(request.request, response.response, () => {\n return resolve(next())\n })\n })\n }\n}\n"],"mappings":";AAuBA,IAAqB,iBAArB,MAAoC;AAAA,EAGlC,YAAsB,MAAY;AAAZ;AACpB,SAAK,aAAa,KAAK,KAAK,aAAa;AAAA,EAC3C;AAAA,EAJA;AAAA,EAMA,MAAM,OAAO,EAAE,SAAS,SAAS,GAAgB,MAAc;AAC7D,WAAO,MAAM,IAAI,QAAQ,CAAC,YAAY;AACpC,WAAK,WAAW,YAAY,OAAO,QAAQ,SAAS,SAAS,UAAU,MAAM;AAC3E,eAAO,QAAQ,KAAK,CAAC;AAAA,MACvB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
File without changes
|