@adonisjs/vite 2.0.2 → 3.0.0-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.
Files changed (47) hide show
  1. package/LICENSE.md +1 -1
  2. package/build/index.d.ts +2 -2
  3. package/build/index.js +47 -12
  4. package/build/providers/vite_provider.d.ts +4 -10
  5. package/build/providers/vite_provider.js +49 -78
  6. package/build/providers/vite_provider.js.map +1 -0
  7. package/build/services/vite.d.ts +1 -1
  8. package/build/services/vite.js +8 -16
  9. package/build/services/vite.js.map +1 -0
  10. package/build/src/client/config.d.ts +13 -2
  11. package/build/src/client/main.d.ts +1 -1
  12. package/build/src/client/main.js +67 -22
  13. package/build/src/client/main.js.map +1 -0
  14. package/build/src/client/types.d.ts +12 -21
  15. package/build/src/define_config.d.ts +5 -0
  16. package/build/src/hooks/build_hook.d.ts +8 -0
  17. package/build/src/hooks/build_hook.js +16 -0
  18. package/build/src/hooks/build_hook.js.map +1 -0
  19. package/build/src/middlewares/vite_middleware.d.ts +17 -0
  20. package/build/src/{backend/types.d.ts → types.d.ts} +6 -22
  21. package/build/src/types.js +1 -0
  22. package/build/src/types.js.map +1 -0
  23. package/build/src/{backend/utils.d.ts → utils.d.ts} +4 -0
  24. package/build/src/{backend/vite.d.ts → vite.d.ts} +27 -9
  25. package/build/stubs/vite.config.stub +1 -1
  26. package/package.json +52 -55
  27. package/build/configure.js +0 -42
  28. package/build/src/backend/debug.d.ts +0 -3
  29. package/build/src/backend/debug.js +0 -10
  30. package/build/src/backend/define_config.d.ts +0 -5
  31. package/build/src/backend/define_config.js +0 -23
  32. package/build/src/backend/plugins/edge.js +0 -86
  33. package/build/src/backend/types.js +0 -9
  34. package/build/src/backend/utils.js +0 -36
  35. package/build/src/backend/vite.js +0 -259
  36. package/build/src/client/config.js +0 -73
  37. package/build/src/client/config_resolver.d.ts +0 -20
  38. package/build/src/client/config_resolver.js +0 -46
  39. package/build/src/client/helpers/inertia.d.ts +0 -4
  40. package/build/src/client/helpers/inertia.js +0 -22
  41. package/build/src/client/hot_file.d.ts +0 -14
  42. package/build/src/client/hot_file.js +0 -49
  43. package/build/src/client/types.js +0 -9
  44. package/build/src/client/utils.d.ts +0 -11
  45. package/build/src/client/utils.js +0 -44
  46. package/build/stubs/main.js +0 -10
  47. /package/build/src/{backend/plugins → plugins}/edge.d.ts +0 -0
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The MIT License
2
2
 
3
- Copyright 2022 Harminder Virk, contributors
3
+ Copyright (c) 2023
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
+ export { Vite } from './src/vite.js';
1
2
  export { configure } from './configure.js';
2
- export { Vite } from './src/backend/vite.js';
3
3
  export { stubsRoot } from './stubs/main.js';
4
- export { defineConfig } from './src/backend/define_config.js';
4
+ export { defineConfig } from './src/define_config.js';
package/build/index.js CHANGED
@@ -1,12 +1,47 @@
1
- /*
2
- * @adonisjs/vite
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- export { configure } from './configure.js';
10
- export { Vite } from './src/backend/vite.js';
11
- export { stubsRoot } from './stubs/main.js';
12
- export { defineConfig } from './src/backend/define_config.js';
1
+ import {
2
+ Vite
3
+ } from "./chunk-J6JUW6YH.js";
4
+ import "./chunk-CFRBPZ4N.js";
5
+
6
+ // stubs/main.ts
7
+ import { getDirname } from "@poppinss/utils";
8
+ var stubsRoot = getDirname(import.meta.url);
9
+
10
+ // configure.ts
11
+ async function configure(command) {
12
+ const codemods = await command.createCodemods();
13
+ let shouldInstallPackages = command.parsedFlags.install;
14
+ await codemods.makeUsingStub(stubsRoot, "config/vite.stub", {});
15
+ await codemods.makeUsingStub(stubsRoot, "vite.config.stub", {});
16
+ await codemods.makeUsingStub(stubsRoot, "js_entrypoint.stub", {});
17
+ await codemods.updateRcFile((rcFile) => {
18
+ rcFile.addProvider("@adonisjs/vite/vite_provider");
19
+ rcFile.addMetaFile("public/**", false);
20
+ });
21
+ if (shouldInstallPackages === void 0) {
22
+ shouldInstallPackages = await command.prompt.confirm('Do you want to install "vite"?');
23
+ }
24
+ if (shouldInstallPackages) {
25
+ await codemods.installPackages([{ name: "vite", isDevDependency: true }]);
26
+ } else {
27
+ await codemods.listPackagesToInstall([{ name: "vite", isDevDependency: true }]);
28
+ }
29
+ }
30
+
31
+ // src/define_config.ts
32
+ import { join } from "node:path";
33
+ function defineConfig(config) {
34
+ return {
35
+ buildDirectory: "public/assets",
36
+ assetsUrl: "/assets",
37
+ manifestFile: config.buildDirectory ? join(config.buildDirectory, ".vite/manifest.json") : "public/assets/.vite/manifest.json",
38
+ ...config
39
+ };
40
+ }
41
+ export {
42
+ Vite,
43
+ configure,
44
+ defineConfig,
45
+ stubsRoot
46
+ };
47
+ //# sourceMappingURL=index.js.map
@@ -1,24 +1,18 @@
1
1
  import type { ApplicationService } from '@adonisjs/core/types';
2
- import { Vite } from '../src/backend/vite.js';
3
- /**
4
- * Extend the container bindings
5
- */
2
+ import { Vite } from '../src/vite.js';
6
3
  declare module '@adonisjs/core/types' {
7
4
  interface ContainerBindings {
8
5
  vite: Vite;
9
6
  }
10
7
  }
11
- export default class ViteServiceProvider {
8
+ export default class ViteProvider {
12
9
  protected app: ApplicationService;
13
10
  constructor(app: ApplicationService);
14
11
  /**
15
12
  * Registers edge plugin when edge is installed
16
13
  */
17
14
  protected registerEdgePlugin(): Promise<void>;
18
- /**
19
- * Registers CSP keywords when @adonisjs/shield is installed
20
- */
21
- protected registerShieldKeywords(): Promise<void>;
22
- register(): void;
15
+ register(): Promise<void>;
23
16
  boot(): Promise<void>;
17
+ shutdown(): Promise<void>;
24
18
  }
@@ -1,80 +1,51 @@
1
- /*
2
- * @adonisjs/vite
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import debug from '../src/backend/debug.js';
10
- import { Vite } from '../src/backend/vite.js';
11
- import { defineConfig } from '../src/backend/define_config.js';
12
- export default class ViteServiceProvider {
13
- app;
14
- constructor(app) {
15
- this.app = app;
1
+ import {
2
+ Vite
3
+ } from "../chunk-J6JUW6YH.js";
4
+ import "../chunk-CFRBPZ4N.js";
5
+ import {
6
+ ViteMiddleware
7
+ } from "../chunk-YCD5RGKQ.js";
8
+
9
+ // providers/vite_provider.ts
10
+ var ViteProvider = class {
11
+ constructor(app) {
12
+ this.app = app;
13
+ }
14
+ /**
15
+ * Registers edge plugin when edge is installed
16
+ */
17
+ async registerEdgePlugin() {
18
+ if (this.app.usingEdgeJS) {
19
+ const edge = await import("edge.js");
20
+ const vite = await this.app.container.make("vite");
21
+ const { edgePluginVite } = await import("../edge-SDXKV2NF.js");
22
+ edge.default.use(edgePluginVite(vite));
16
23
  }
17
- /**
18
- * Registers edge plugin when edge is installed
19
- */
20
- async registerEdgePlugin() {
21
- if (this.app.usingEdgeJS) {
22
- const edge = await import('edge.js');
23
- const vite = await this.app.container.make('vite');
24
- const { edgePluginVite } = await import('../src/backend/plugins/edge.js');
25
- edge.default.use(edgePluginVite(vite));
26
- }
24
+ }
25
+ async register() {
26
+ const config = this.app.config.get("vite");
27
+ const vite = new Vite(this.app.inDev, config);
28
+ this.app.container.bind("vite", () => vite);
29
+ this.app.container.bind(ViteMiddleware, () => new ViteMiddleware(vite));
30
+ if (this.app.inDev) {
31
+ const server = await this.app.container.make("server");
32
+ server.use([() => import("../vite_middleware-HYLIJP2B.js")]);
27
33
  }
28
- /**
29
- * Registers CSP keywords when @adonisjs/shield is installed
30
- */
31
- async registerShieldKeywords() {
32
- let cspKeywords = null;
33
- try {
34
- const shieldExports = await import('@adonisjs/shield');
35
- cspKeywords = shieldExports.cspKeywords;
36
- }
37
- catch { }
38
- if (cspKeywords) {
39
- debug('Detected @adonisjs/shield package. Adding Vite keywords for CSP policy');
40
- const vite = await this.app.container.make('vite');
41
- /**
42
- * Registering the @viteUrl keyword for CSP directives.
43
- * Returns http URL to the dev or the CDN server, otherwise
44
- * an empty string
45
- */
46
- cspKeywords.register('@viteUrl', function () {
47
- const assetsURL = vite.assetsUrl();
48
- if (!assetsURL || !assetsURL.startsWith('http://') || assetsURL.startsWith('https://')) {
49
- return '';
50
- }
51
- return assetsURL;
52
- });
53
- /**
54
- * Registering the @viteDevUrl keyword for the CSP directives.
55
- * Returns the dev server URL in development and empty string
56
- * in prod
57
- */
58
- cspKeywords.register('@viteDevUrl', function () {
59
- return vite.devUrl();
60
- });
61
- /**
62
- * Registering the @viteHmrUrl keyword for the CSP directives.
63
- * Returns the Websocket URL for the HMR server
64
- */
65
- cspKeywords.register('@viteHmrUrl', function () {
66
- return vite.devUrl().replace('http://', 'ws://').replace('https://', 'wss://');
67
- });
68
- }
69
- }
70
- register() {
71
- this.app.container.singleton('vite', async () => {
72
- const config = this.app.config.get('vite', defineConfig({}));
73
- return new Vite(config);
74
- });
75
- }
76
- async boot() {
77
- await this.registerEdgePlugin();
78
- await this.registerShieldKeywords();
79
- }
80
- }
34
+ }
35
+ async boot() {
36
+ if (!this.app.inDev)
37
+ return;
38
+ const vite = await this.app.container.make("vite");
39
+ await Promise.all([vite.createDevServer(), this.registerEdgePlugin()]);
40
+ }
41
+ async shutdown() {
42
+ if (!this.app.inDev)
43
+ return;
44
+ const vite = await this.app.container.make("vite");
45
+ await vite.stopDevServer();
46
+ }
47
+ };
48
+ export {
49
+ ViteProvider as default
50
+ };
51
+ //# sourceMappingURL=vite_provider.js.map
@@ -0,0 +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'\n\nimport { Vite } from '../src/vite.js'\nimport type { ViteOptions } from '../src/types.js'\nimport ViteMiddleware from '../src/middlewares/vite_middleware.js'\n\ndeclare module '@adonisjs/core/types' {\n interface ContainerBindings {\n vite: Vite\n }\n}\n\nexport default class ViteProvider {\n constructor(protected app: ApplicationService) {}\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 async register() {\n const config = this.app.config.get<ViteOptions>('vite')\n\n const vite = new Vite(this.app.inDev, config)\n this.app.container.bind('vite', () => vite)\n this.app.container.bind(ViteMiddleware, () => new ViteMiddleware(vite))\n\n if (this.app.inDev) {\n const server = await this.app.container.make('server')\n server.use([() => import('../src/middlewares/vite_middleware.js')])\n }\n }\n\n async boot() {\n if (!this.app.inDev) return\n\n const vite = await this.app.container.make('vite')\n await Promise.all([vite.createDevServer(), this.registerEdgePlugin()])\n }\n\n async shutdown() {\n if (!this.app.inDev) return\n\n const vite = await this.app.container.make('vite')\n await vite.stopDevServer()\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,IAAqB,eAArB,MAAkC;AAAA,EAChC,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA;AAAA;AAAA;AAAA,EAKhD,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,qBAAwB;AAChE,WAAK,QAAQ,IAAI,eAAe,IAAI,CAAC;AAAA,IACvC;AAAA,EACF;AAAA,EAEA,MAAM,WAAW;AACf,UAAM,SAAS,KAAK,IAAI,OAAO,IAAiB,MAAM;AAEtD,UAAM,OAAO,IAAI,KAAK,KAAK,IAAI,OAAO,MAAM;AAC5C,SAAK,IAAI,UAAU,KAAK,QAAQ,MAAM,IAAI;AAC1C,SAAK,IAAI,UAAU,KAAK,gBAAgB,MAAM,IAAI,eAAe,IAAI,CAAC;AAEtE,QAAI,KAAK,IAAI,OAAO;AAClB,YAAM,SAAS,MAAM,KAAK,IAAI,UAAU,KAAK,QAAQ;AACrD,aAAO,IAAI,CAAC,MAAM,OAAO,gCAAuC,CAAC,CAAC;AAAA,IACpE;AAAA,EACF;AAAA,EAEA,MAAM,OAAO;AACX,QAAI,CAAC,KAAK,IAAI;AAAO;AAErB,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,UAAM,QAAQ,IAAI,CAAC,KAAK,gBAAgB,GAAG,KAAK,mBAAmB,CAAC,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,WAAW;AACf,QAAI,CAAC,KAAK,IAAI;AAAO;AAErB,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,UAAM,KAAK,cAAc;AAAA,EAC3B;AACF;","names":[]}
@@ -1,3 +1,3 @@
1
- import type { Vite } from '../src/backend/vite.js';
1
+ import type { Vite } from '../src/vite.js';
2
2
  declare let vite: Vite;
3
3
  export { vite as default };
@@ -1,18 +1,10 @@
1
- /*
2
- * @adonisjs/vite
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import app from '@adonisjs/core/services/app';
10
- let vite;
11
- /**
12
- * Returns a singleton instance of Vite class
13
- * from the container
14
- */
1
+ // services/vite.ts
2
+ import app from "@adonisjs/core/services/app";
3
+ var vite;
15
4
  await app.booted(async () => {
16
- vite = await app.container.make('vite');
5
+ vite = await app.container.make("vite");
17
6
  });
18
- export { vite as default };
7
+ export {
8
+ vite as default
9
+ };
10
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../services/vite.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 app from '@adonisjs/core/services/app'\nimport type { Vite } from '../src/vite.js'\n\nlet vite: Vite\n\n/**\n * Returns a singleton instance of Vite class\n * from the container\n */\nawait app.booted(async () => {\n vite = await app.container.make('vite')\n})\n\nexport { vite as default }\n"],"mappings":";AASA,OAAO,SAAS;AAGhB,IAAI;AAMJ,MAAM,IAAI,OAAO,YAAY;AAC3B,SAAO,MAAM,IAAI,UAAU,KAAK,MAAM;AACxC,CAAC;","names":[]}
@@ -1,9 +1,20 @@
1
- import { ConfigEnv, Plugin, UserConfig } from 'vite';
1
+ import type { AliasOptions, ConfigEnv, Plugin, UserConfig } from 'vite';
2
2
  import type { PluginFullOptions } from './types.js';
3
+ /**
4
+ * Resolve the `config.resolve.alias` value
5
+ *
6
+ * Basically we are merging the user defined alias with the
7
+ * default alias.
8
+ */
9
+ export declare function resolveAlias(config: UserConfig): AliasOptions;
10
+ /**
11
+ * Resolve the `config.base` value
12
+ */
13
+ export declare function resolveBase(config: UserConfig, options: PluginFullOptions, command: 'build' | 'serve'): string;
3
14
  /**
4
15
  * Vite config hook
5
16
  */
6
- export declare const configHook: (options: PluginFullOptions, userConfig: UserConfig, { command }: ConfigEnv) => UserConfig;
17
+ export declare function configHook(options: PluginFullOptions, userConfig: UserConfig, { command }: ConfigEnv): UserConfig;
7
18
  /**
8
19
  * Update the user vite config to match the Adonis requirements
9
20
  */
@@ -6,6 +6,6 @@ declare module 'vite' {
6
6
  }
7
7
  }
8
8
  /**
9
- * Vite plugin for adonisjs
9
+ * Vite plugin for AdonisJS
10
10
  */
11
11
  export default function adonisjs(options: PluginOptions): PluginOption[];
@@ -1,23 +1,68 @@
1
- /*
2
- * @adonisjs/vite
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { defu } from 'defu';
10
- import PluginRestart from 'vite-plugin-restart';
11
- import { config } from './config.js';
12
- /**
13
- * Vite plugin for adonisjs
14
- */
15
- export default function adonisjs(options) {
16
- const fullOptions = defu(options, {
17
- buildDirectory: 'public/assets',
18
- assetsUrl: '/assets',
19
- hotFile: 'public/assets/hot.json',
20
- reload: ['./resources/views/**/*.edge'],
21
- });
22
- return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)];
1
+ import {
2
+ addTrailingSlash
3
+ } from "../../chunk-CFRBPZ4N.js";
4
+
5
+ // src/client/main.ts
6
+ import PluginRestart from "vite-plugin-restart";
7
+
8
+ // src/client/config.ts
9
+ import { join } from "node:path";
10
+ function resolveAlias(config2) {
11
+ const defaultAlias = { "@/": `/resources/js/` };
12
+ if (Array.isArray(config2.resolve?.alias)) {
13
+ return [
14
+ ...config2.resolve?.alias ?? [],
15
+ Object.entries(defaultAlias).map(([find, replacement]) => ({ find, replacement }))
16
+ ];
17
+ }
18
+ return { ...defaultAlias, ...config2.resolve?.alias };
23
19
  }
20
+ function resolveBase(config2, options, command) {
21
+ if (config2.base)
22
+ return config2.base;
23
+ if (command === "build") {
24
+ return addTrailingSlash(options.assetsUrl);
25
+ }
26
+ return "/";
27
+ }
28
+ function configHook(options, userConfig, { command }) {
29
+ const config2 = {
30
+ publicDir: userConfig.publicDir ?? false,
31
+ resolve: { alias: resolveAlias(userConfig) },
32
+ base: resolveBase(userConfig, options, command),
33
+ build: {
34
+ assetsDir: "",
35
+ emptyOutDir: true,
36
+ manifest: userConfig.build?.manifest ?? true,
37
+ outDir: userConfig.build?.outDir ?? options.buildDirectory,
38
+ assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,
39
+ rollupOptions: {
40
+ input: options.entrypoints.map((entrypoint) => join(userConfig.root || "", entrypoint))
41
+ }
42
+ }
43
+ };
44
+ return config2;
45
+ }
46
+ var config = (options) => {
47
+ return {
48
+ name: "vite-plugin-adonis:config",
49
+ config: configHook.bind(null, options)
50
+ };
51
+ };
52
+
53
+ // src/client/main.ts
54
+ function adonisjs(options) {
55
+ const fullOptions = Object.assign(
56
+ {
57
+ assetsUrl: "/assets",
58
+ buildDirectory: "public/assets",
59
+ reload: ["./resources/views/**/*.edge"]
60
+ },
61
+ options
62
+ );
63
+ return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)];
64
+ }
65
+ export {
66
+ adonisjs as default
67
+ };
68
+ //# sourceMappingURL=main.js.map
@@ -0,0 +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 { AliasOptions, ConfigEnv, Plugin, UserConfig } from 'vite'\n\nimport { addTrailingSlash } from '../utils.js'\nimport type { PluginFullOptions } from './types.js'\n\n/**\n * Resolve the `config.resolve.alias` value\n *\n * Basically we are merging the user defined alias with the\n * default alias.\n */\nexport function resolveAlias(config: UserConfig): AliasOptions {\n const defaultAlias = { '@/': `/resources/js/` }\n\n if (Array.isArray(config.resolve?.alias)) {\n return [\n ...(config.resolve?.alias ?? []),\n Object.entries(defaultAlias).map(([find, replacement]) => ({ find, replacement })),\n ]\n }\n\n return { ...defaultAlias, ...config.resolve?.alias }\n}\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 resolve: { alias: resolveAlias(userConfig) },\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 config: configHook.bind(null, options),\n }\n}\n"],"mappings":";;;;;AAYA,OAAO,mBAAmB;;;ACH1B,SAAS,YAAY;AAYd,SAAS,aAAaA,SAAkC;AAC7D,QAAM,eAAe,EAAE,MAAM,iBAAiB;AAE9C,MAAI,MAAM,QAAQA,QAAO,SAAS,KAAK,GAAG;AACxC,WAAO;AAAA,MACL,GAAIA,QAAO,SAAS,SAAS,CAAC;AAAA,MAC9B,OAAO,QAAQ,YAAY,EAAE,IAAI,CAAC,CAAC,MAAM,WAAW,OAAO,EAAE,MAAM,YAAY,EAAE;AAAA,IACnF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAGA,QAAO,SAAS,MAAM;AACrD;AAKO,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,SAAS,EAAE,OAAO,aAAa,UAAU,EAAE;AAAA,IAC3C,MAAM,YAAY,YAAY,SAAS,OAAO;AAAA,IAE9C,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,QAAQ,WAAW,KAAK,MAAM,OAAO;AAAA,EACvC;AACF;;;AD7De,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,17 +1,4 @@
1
- /**
2
- * Possible plugin options
3
- */
4
- export type PluginOptions = {
5
- /**
6
- * Path to the hot file
7
- *
8
- * @default public/hot.json
9
- */
10
- hotFile?: string;
11
- /**
12
- * Paths to the entrypoints files
13
- */
14
- entrypoints: string[];
1
+ export interface PluginOptions {
15
2
  /**
16
3
  * The URL where the assets will be served. This is particularly
17
4
  * useful if you are using a CDN to deploy your assets.
@@ -19,17 +6,21 @@ export type PluginOptions = {
19
6
  * @default ''
20
7
  */
21
8
  assetsUrl?: string;
22
- /**
23
- * Public directory where the assets will be compiled.
24
- *
25
- * @default 'public/assets'
26
- */
27
- buildDirectory?: string;
28
9
  /**
29
10
  * Files that should trigger a page reload when changed.
30
11
  *
31
12
  * @default ['./resources/views/** /*.edge']
32
13
  */
33
14
  reload?: string[];
34
- };
15
+ /**
16
+ * Paths to the entrypoints files
17
+ */
18
+ entrypoints: string[];
19
+ /**
20
+ * Public directory where the assets will be compiled.
21
+ *
22
+ * @default 'public/assets'
23
+ */
24
+ buildDirectory?: string;
25
+ }
35
26
  export type PluginFullOptions = Required<PluginOptions>;
@@ -0,0 +1,5 @@
1
+ import type { ViteOptions } from './types.js';
2
+ /**
3
+ * Define the backend config for Vite
4
+ */
5
+ export declare function defineConfig(config: Partial<ViteOptions>): ViteOptions;
@@ -0,0 +1,8 @@
1
+ import type { AssemblerHookHandler } from '@adonisjs/application/types';
2
+ /**
3
+ * This is an Assembler hook that should be executed when the application is
4
+ * builded using the `node ace build` command.
5
+ *
6
+ * The hook is responsible for launching a Vite multi-build process.
7
+ */
8
+ export default function viteBuildHook({ logger }: Parameters<AssemblerHookHandler>[0]): Promise<void>;
@@ -0,0 +1,16 @@
1
+ // src/hooks/build_hook.ts
2
+ import { multibuild } from "@vavite/multibuild";
3
+ async function viteBuildHook({ logger }) {
4
+ logger.info("building assets with vite");
5
+ await multibuild(void 0, {
6
+ onStartBuildStep: (step) => {
7
+ if (!step.currentStep.description)
8
+ return;
9
+ logger.info(step.currentStep.description);
10
+ }
11
+ });
12
+ }
13
+ export {
14
+ viteBuildHook as default
15
+ };
16
+ //# sourceMappingURL=build_hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/build_hook.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 { multibuild } from '@vavite/multibuild'\nimport type { AssemblerHookHandler } from '@adonisjs/application/types'\n\n/**\n * This is an Assembler hook that should be executed when the application is\n * builded using the `node ace build` command.\n *\n * The hook is responsible for launching a Vite multi-build process.\n */\nexport default async function viteBuildHook({ logger }: Parameters<AssemblerHookHandler>[0]) {\n logger.info('building assets with vite')\n\n await multibuild(undefined, {\n onStartBuildStep: (step) => {\n if (!step.currentStep.description) return\n\n logger.info(step.currentStep.description)\n },\n })\n}\n"],"mappings":";AASA,SAAS,kBAAkB;AAS3B,eAAO,cAAqC,EAAE,OAAO,GAAwC;AAC3F,SAAO,KAAK,2BAA2B;AAEvC,QAAM,WAAW,QAAW;AAAA,IAC1B,kBAAkB,CAAC,SAAS;AAC1B,UAAI,CAAC,KAAK,YAAY;AAAa;AAEnC,aAAO,KAAK,KAAK,YAAY,WAAW;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,17 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ import type { NextFn } from '@adonisjs/core/types/http';
3
+ import type { Vite } from '../vite.js';
4
+ /**
5
+ * Since Vite dev server is integrated within the AdonisJS process, this
6
+ * middleware is used to proxy the requests to it.
7
+ *
8
+ * Some of the requests are directly handled by the Vite dev server,
9
+ * like the one for the assets, while others are passed down to the
10
+ * AdonisJS server.
11
+ */
12
+ export default class ViteMiddleware {
13
+ #private;
14
+ protected vite: Vite;
15
+ constructor(vite: Vite);
16
+ handle({ request, response }: HttpContext, next: NextFn): Promise<unknown>;
17
+ }
@@ -1,9 +1,3 @@
1
- /**
2
- * Contents of the hotfile
3
- */
4
- export type HotFile = {
5
- url: string;
6
- };
7
1
  /**
8
2
  * Parameters passed to the setAttributes callback
9
3
  */
@@ -28,17 +22,7 @@ export type AdonisViteElement = {
28
22
  attributes: Record<string, any>;
29
23
  children: string[];
30
24
  };
31
- /**
32
- * Vite backend integration configuration options
33
- */
34
- export type ViteOptions = {
35
- /**
36
- * Path to the hot file relative from the root of the
37
- * application.
38
- *
39
- * @default public/assets/hot.json
40
- */
41
- hotFile: string;
25
+ export interface ViteOptions {
42
26
  /**
43
27
  * Public directory where the assets will be compiled.
44
28
  *
@@ -61,12 +45,12 @@ export type ViteOptions = {
61
45
  assetsUrl?: string;
62
46
  /**
63
47
  * A custom set of attributes to apply on all
64
- * script tags
48
+ * script tags injected by edge `@vite` tag
65
49
  */
66
- scriptAttributes?: SetAttributes;
50
+ styleAttributes?: SetAttributes;
67
51
  /**
68
52
  * A custom set of attributes to apply on all
69
- * style tags
53
+ * style tags injected by edge `@vite` tag
70
54
  */
71
- styleAttributes?: SetAttributes;
72
- };
55
+ scriptAttributes?: SetAttributes;
56
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -6,3 +6,7 @@ export declare function uniqBy<T>(array: T[], key: keyof T): T[];
6
6
  * Convert Record of attributes to a valid HTML string
7
7
  */
8
8
  export declare function makeAttributes(attributes: Record<string, string | boolean>): string;
9
+ /**
10
+ * Add a trailing slash if missing
11
+ */
12
+ export declare const addTrailingSlash: (url: string) => string;
@@ -1,4 +1,5 @@
1
- import type { Manifest } from 'vite';
1
+ import type { ViteRuntime } from 'vite/runtime';
2
+ import type { Manifest, ViteDevServer } from 'vite';
2
3
  import type { AdonisViteElement, ViteOptions } from './types.js';
3
4
  /**
4
5
  * Vite class exposes the APIs to generate tags and URLs for
@@ -6,22 +7,18 @@ import type { AdonisViteElement, ViteOptions } from './types.js';
6
7
  */
7
8
  export declare class Vite {
8
9
  #private;
9
- constructor(options: ViteOptions);
10
+ protected inDev: boolean;
11
+ constructor(inDev: boolean, options: ViteOptions);
10
12
  /**
11
13
  * Generate tags for the entry points
12
14
  */
13
15
  generateEntryPointsTags(entryPoints: string[] | string, attributes?: Record<string, any>): AdonisViteElement[];
14
- /**
15
- * Returns the dev server URL when running in hot
16
- * mode. Otherwise an empty string
17
- */
18
- devUrl(): string;
19
16
  /**
20
17
  * Returns the dev server URL when running in hot
21
18
  * mode, otherwise returns the explicitly configured
22
19
  * "assets" URL
23
20
  */
24
- assetsUrl(): string | undefined;
21
+ assetsUrl(): string | boolean | undefined;
25
22
  /**
26
23
  * Returns path to a given asset file
27
24
  */
@@ -29,9 +26,30 @@ export declare class Vite {
29
26
  /**
30
27
  * Returns the manifest file contents
31
28
  *
32
- * @throws Will throw an exception when running in hot mode
29
+ * @throws Will throw an exception when running in dev
33
30
  */
34
31
  manifest(): Manifest;
32
+ /**
33
+ * Create the Vite Dev Server and runtime
34
+ *
35
+ * We lazy load the APIs to avoid loading it in production
36
+ * since we don't need it
37
+ */
38
+ createDevServer(): Promise<void>;
39
+ /**
40
+ * Stop the Vite Dev server
41
+ */
42
+ stopDevServer(): Promise<void>;
43
+ /**
44
+ * Get the Vite Dev server instance
45
+ * Will not be available when running in production
46
+ */
47
+ getDevServer(): ViteDevServer | undefined;
48
+ /**
49
+ * Get the Vite runtime instance
50
+ * Will not be available when running in production
51
+ */
52
+ getRuntime(): ViteRuntime | undefined;
35
53
  /**
36
54
  * Returns the script needed for the HMR working with React
37
55
  */