@adonisjs/inertia 1.0.0-7 → 1.0.0-8

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.
@@ -0,0 +1,39 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/css/app.css') })
3
+ }}}
4
+ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap');
5
+
6
+ * {
7
+ margin: 0;
8
+ padding: 0;
9
+ }
10
+
11
+ html,
12
+ body,
13
+ #app {
14
+ background-color: #F7F8FA;
15
+ font-family: 'Poppins', sans-serif;
16
+ color: #46444c;
17
+ height: 100%;
18
+ width: 100%;
19
+ }
20
+
21
+ .title {
22
+ font-size: 42px;
23
+ font-weight: 500;
24
+ color: #5a45ff;
25
+ }
26
+
27
+ .container {
28
+ display: flex;
29
+ justify-content: center;
30
+ align-items: center;
31
+ flex-direction: column;
32
+ height: 100%;
33
+ width: 100%;
34
+ }
35
+
36
+ a {
37
+ text-decoration: underline;
38
+ color: #5a45ff;
39
+ }
@@ -1,9 +1,10 @@
1
1
  // src/inertia.ts
2
2
  var kLazySymbol = Symbol("lazy");
3
3
  var Inertia = class {
4
- constructor(ctx, config) {
4
+ constructor(ctx, config, viteRuntime) {
5
5
  this.ctx = ctx;
6
6
  this.config = config;
7
+ this.viteRuntime = viteRuntime;
7
8
  this.#sharedData = config.sharedData;
8
9
  }
9
10
  #sharedData = {};
@@ -60,6 +61,33 @@ var Inertia = class {
60
61
  url: this.ctx.request.url(true)
61
62
  };
62
63
  }
64
+ /**
65
+ * If the page should be rendered on the server
66
+ */
67
+ #shouldRenderOnServer(component) {
68
+ const isSsrEnabled = this.config.ssr.enabled;
69
+ const isSsrEnabledForPage = this.config.ssr.pages ? this.config.ssr.pages.includes(component) : true;
70
+ return isSsrEnabled && isSsrEnabledForPage;
71
+ }
72
+ /**
73
+ * Render the page on the server
74
+ *
75
+ * On development, we use the Vite Runtime API
76
+ * On production, we just import and use the SSR bundle generated by Vite
77
+ */
78
+ async #renderOnServer(pageObject, viewProps) {
79
+ let render;
80
+ if (this.viteRuntime) {
81
+ render = await this.viteRuntime.executeEntrypoint(this.config.ssr.entrypoint);
82
+ } else {
83
+ render = await import(this.config.ssr.bundle);
84
+ }
85
+ const result = await render.default(pageObject);
86
+ return this.ctx.view.render(this.config.rootView, {
87
+ ...viewProps,
88
+ page: { ssrHead: result.head, ssrBody: result.body }
89
+ });
90
+ }
63
91
  /**
64
92
  * Share data for the current request.
65
93
  * This data will override any shared data defined in the config.
@@ -74,6 +102,9 @@ var Inertia = class {
74
102
  const pageObject = await this.#buildPageObject(component, pageProps);
75
103
  const isInertiaRequest = !!this.ctx.request.header("x-inertia");
76
104
  if (!isInertiaRequest) {
105
+ const shouldRenderOnServer = this.#shouldRenderOnServer(component);
106
+ if (shouldRenderOnServer)
107
+ return this.#renderOnServer(pageObject, viewProps);
77
108
  return this.ctx.view.render(this.config.rootView, { ...viewProps, page: pageObject });
78
109
  }
79
110
  this.ctx.response.header("x-inertia", "true");
@@ -104,12 +135,14 @@ var Inertia = class {
104
135
 
105
136
  // src/inertia_middleware.ts
106
137
  var InertiaMiddleware = class {
107
- constructor(config) {
138
+ constructor(config, vite) {
108
139
  this.config = config;
140
+ this.#runtime = vite?.getRuntime();
109
141
  }
142
+ #runtime;
110
143
  async handle(ctx, next) {
111
144
  const { response, request } = ctx;
112
- ctx.inertia = new Inertia(ctx, this.config);
145
+ ctx.inertia = new Inertia(ctx, this.config, this.#runtime);
113
146
  await next();
114
147
  const isInertiaRequest = !!request.header("x-inertia");
115
148
  if (!isInertiaRequest)
package/build/config.stub CHANGED
@@ -7,7 +7,7 @@ export default defineConfig({
7
7
  /**
8
8
  * Path to the Edge view that will be used as the root view for Inertia responses
9
9
  */
10
- rootView: 'home',
10
+ rootView: 'root',
11
11
 
12
12
  /**
13
13
  * Data that should be shared with all rendered pages
package/build/index.js CHANGED
@@ -3,16 +3,26 @@ import { getDirname } from "@poppinss/utils";
3
3
  var stubsRoot = getDirname(import.meta.url);
4
4
 
5
5
  // configure.ts
6
- var ADAPTERS = ["Vue 3", "React", "Svelte"];
6
+ var ADAPTERS = ["Vue 3", "React", "Svelte", "Solid"];
7
7
  var ADAPTERS_INFO = {
8
8
  "Vue 3": {
9
+ stubFolder: "vue",
10
+ appExtension: "ts",
11
+ componentsExtension: "vue",
9
12
  dependencies: [
10
13
  { name: "@inertiajs/vue3", isDevDependency: false },
11
14
  { name: "vue", isDevDependency: false },
12
15
  { name: "@vitejs/plugin-vue", isDevDependency: true }
13
- ]
16
+ ],
17
+ viteRegister: {
18
+ pluginCall: "vue()",
19
+ importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-vue", identifier: "vue" }]
20
+ }
14
21
  },
15
22
  "React": {
23
+ stubFolder: "react",
24
+ appExtension: "tsx",
25
+ componentsExtension: "tsx",
16
26
  dependencies: [
17
27
  { name: "@inertiajs/react", isDevDependency: false },
18
28
  { name: "react", isDevDependency: false },
@@ -20,29 +30,76 @@ var ADAPTERS_INFO = {
20
30
  { name: "@vitejs/plugin-react", isDevDependency: true },
21
31
  { name: "@types/react", isDevDependency: true },
22
32
  { name: "@types/react-dom", isDevDependency: true }
23
- ]
33
+ ],
34
+ viteRegister: {
35
+ pluginCall: "react()",
36
+ importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-react", identifier: "react" }]
37
+ }
24
38
  },
25
39
  "Svelte": {
40
+ stubFolder: "svelte",
41
+ appExtension: "ts",
42
+ componentsExtension: "svelte",
26
43
  dependencies: [
27
44
  { name: "@inertiajs/svelte", isDevDependency: false },
28
45
  { name: "svelte", isDevDependency: false },
29
46
  { name: "@sveltejs/vite-plugin-svelte", isDevDependency: true }
30
- ]
47
+ ],
48
+ viteRegister: {
49
+ pluginCall: "svelte()",
50
+ importDeclarations: [
51
+ { isNamed: false, module: "@sveltejs/vite-plugin-svelte", identifier: "svelte" }
52
+ ]
53
+ }
54
+ },
55
+ "Solid": {
56
+ stubFolder: "solid",
57
+ appExtension: "tsx",
58
+ componentsExtension: "tsx",
59
+ dependencies: [
60
+ { name: "solid-js", isDevDependency: false },
61
+ { name: "inertia-adapter-solid", isDevDependency: false },
62
+ { name: "vite-plugin-solid", isDevDependency: true },
63
+ { name: "@solidjs/meta", isDevDependency: false }
64
+ ],
65
+ viteRegister: {
66
+ pluginCall: "solid()",
67
+ importDeclarations: [{ isNamed: false, module: "vite-plugin-solid", identifier: "solid" }]
68
+ }
31
69
  }
32
70
  };
71
+ async function defineExampleRoute(command, codemods) {
72
+ const tsMorph = await codemods.getTsMorphProject();
73
+ const routesFile = tsMorph?.getSourceFile(command.app.makePath("./start/routes.ts"));
74
+ if (!routesFile) {
75
+ return command.logger.warning("Unable to find the routes file");
76
+ }
77
+ const isAlreadyDefined = routesFile.getText().includes("/inertia");
78
+ if (isAlreadyDefined) {
79
+ command.logger.warning("/inertia route is already defined. Skipping");
80
+ return;
81
+ }
82
+ const action = command.logger.action("update start/routes.ts file");
83
+ try {
84
+ routesFile?.addStatements((writer) => {
85
+ writer.writeLine(
86
+ `router.get('/inertia', ({ inertia }) => inertia.render('home', { version: 6 }))`
87
+ );
88
+ });
89
+ await tsMorph?.save();
90
+ action.succeeded();
91
+ } catch (error) {
92
+ codemods.emit("error", error);
93
+ action.failed(error.message);
94
+ }
95
+ }
33
96
  async function configure(command) {
34
97
  const adapter = await command.prompt.choice(
35
98
  "Select the Inertia adapter you want to use",
36
99
  ADAPTERS,
37
100
  { name: "adapter" }
38
101
  );
39
- const pkgToInstall = ADAPTERS_INFO[adapter].dependencies;
40
- const withSsr = await command.prompt.confirm("Do you want to enable server-side rendering?", {
41
- name: "ssr"
42
- });
43
- if (withSsr) {
44
- pkgToInstall.push(...ADAPTERS_INFO[adapter].ssrDependencies || []);
45
- }
102
+ const adapterInfo = ADAPTERS_INFO[adapter];
46
103
  const codemods = await command.createCodemods();
47
104
  await codemods.updateRcFile((rcFile) => {
48
105
  rcFile.addProvider("@adonisjs/inertia/inertia_provider");
@@ -50,7 +107,21 @@ async function configure(command) {
50
107
  await codemods.registerMiddleware("router", [
51
108
  { path: "@adonisjs/inertia/inertia_middleware", position: "after" }
52
109
  ]);
110
+ const appExt = adapterInfo.appExtension;
111
+ const stubFolder = adapterInfo.stubFolder;
112
+ const compExt = adapterInfo.componentsExtension;
53
113
  await codemods.makeUsingStub(stubsRoot, "config.stub", {});
114
+ await codemods.makeUsingStub(stubsRoot, `app.css.stub`, {});
115
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/root.edge.stub`, {});
116
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/tsconfig.json.stub`, {});
117
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/app.${appExt}.stub`, {});
118
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/home.${compExt}.stub`, {});
119
+ await codemods.registerVitePlugin(
120
+ adapterInfo.viteRegister.pluginCall,
121
+ adapterInfo.viteRegister.importDeclarations
122
+ );
123
+ defineExampleRoute(command, codemods);
124
+ const pkgToInstall = adapterInfo.dependencies;
54
125
  const shouldInstallPackages = await command.prompt.confirm(
55
126
  `Do you want to install dependencies ${pkgToInstall.map((pkg) => pkg.name).join(", ")}?`,
56
127
  { name: "install" }
@@ -60,9 +131,7 @@ async function configure(command) {
60
131
  } else {
61
132
  await codemods.listPackagesToInstall(pkgToInstall);
62
133
  }
63
- command.logger.success(
64
- "Inertia was configured successfully. Please note that you still need to update your vite config, setup your Edge root view and others things. Read the docs for more info."
65
- );
134
+ command.logger.success("Inertia configured");
66
135
  }
67
136
 
68
137
  // src/define_config.ts
@@ -124,7 +193,13 @@ function defineConfig(config) {
124
193
  return {
125
194
  rootView: config.rootView ?? "root",
126
195
  sharedData: config.sharedData || {},
127
- versionCache
196
+ versionCache,
197
+ ssr: {
198
+ enabled: config.ssr?.enabled ?? false,
199
+ pages: config.ssr?.pages,
200
+ entrypoint: config.ssr?.entrypoint ?? app.makePath("resources/ssr.ts"),
201
+ bundle: config.ssr?.bundle ?? app.makePath("ssr/ssr.js")
202
+ }
128
203
  };
129
204
  });
130
205
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-RXGBTZMN.js";
3
+ } from "../chunk-CXICUKHN.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
@@ -26,12 +26,13 @@ var InertiaProvider = class {
26
26
  this.app.container.singleton(InertiaMiddleware, async () => {
27
27
  const inertiaConfigProvider = this.app.config.get("inertia");
28
28
  const config = await configProvider.resolve(this.app, inertiaConfigProvider);
29
+ const vite = await this.app.container.make("vite");
29
30
  if (!config) {
30
31
  throw new RuntimeException(
31
32
  'Invalid "config/inertia.ts" file. Make sure you are using the "defineConfig" method'
32
33
  );
33
34
  }
34
- return new InertiaMiddleware(config);
35
+ return new InertiaMiddleware(config, vite);
35
36
  });
36
37
  await this.registerEdgePlugin();
37
38
  }
@@ -0,0 +1,25 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.tsx') })
3
+ }}}
4
+ import './css/app.css';
5
+
6
+ import { createRoot } from 'react-dom/client';
7
+ import { createInertiaApp } from '@inertiajs/react';
8
+
9
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
10
+
11
+ createInertiaApp({
12
+ progress: { color: '#5468FF' },
13
+
14
+ title: (title) => {{ '`${title} - ${appName}`' }},
15
+
16
+ resolve: (name) => {
17
+ const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
18
+ {{ 'return pages[`./pages/${name}.tsx`]' }}
19
+ },
20
+
21
+ setup({ el, App, props }) {
22
+ const root = createRoot(el);
23
+ root.render(<App {...props} />);
24
+ },
25
+ });
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.tsx') })
3
+ }}}
4
+ import { Head } from '@inertiajs/react'
5
+
6
+ export default function Home(props: { version: number }) {
7
+ return (
8
+ <>
9
+ <Head title="Homepage" />
10
+
11
+ <div className="container">
12
+ <div className="title">AdonisJS {props.version} x Inertia x React</div>
13
+
14
+ <span>
15
+ Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
+ <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
17
+ </span>
18
+ </div>
19
+ </>
20
+ )
21
+ }
@@ -0,0 +1,22 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/root.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x React</title>
12
+
13
+ @viteReactRefresh()
14
+ @vite(['resources/app.tsx'])
15
+ @inertiaHead()
16
+ </head>
17
+
18
+ <body>
19
+ @inertia()
20
+ </body>
21
+
22
+ </html>
@@ -0,0 +1,25 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "compilerOptions": {
6
+ "target": "ESNext",
7
+ "jsx": "react-jsx",
8
+ "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
9
+ "useDefineForClassFields": true,
10
+ "baseUrl": ".",
11
+ "module": "ESNext",
12
+ "moduleResolution": "Bundler",
13
+ "paths": {
14
+ "@/*": ["./*"],
15
+ "~/*": ["../*"],
16
+ },
17
+ "resolveJsonModule": true,
18
+ "types": ["vite/client"],
19
+ "allowSyntheticDefaultImports": true,
20
+ "esModuleInterop": true,
21
+ "verbatimModuleSyntax": true,
22
+ "skipLibCheck": true,
23
+ },
24
+ "include": ["./**/*.ts", "./**/*.tsx", "app.tsx.stub"],
25
+ }
@@ -0,0 +1,24 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.tsx') })
3
+ }}}
4
+ import './css/app.css'
5
+
6
+ import { render } from 'solid-js/web'
7
+ import { createInertiaApp } from 'inertia-adapter-solid'
8
+
9
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
10
+
11
+ createInertiaApp({
12
+ progress: { color: '#5468FF' },
13
+
14
+ title: (title) => {{ '`${title} - ${appName}`' }},
15
+
16
+ resolve(name) {
17
+ const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
18
+ {{ 'return pages[`./pages/${name}.tsx`]' }}
19
+ },
20
+
21
+ setup({ el, App, props }) {
22
+ render(() => <App {...props} />, el)
23
+ },
24
+ })
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.tsx') })
3
+ }}}
4
+ import { Title } from '@solidjs/meta'
5
+
6
+ export default function Home(props: { version: number }) {
7
+ return (
8
+ <>
9
+ <Title>Homepage</Title>
10
+
11
+ <div class="container">
12
+ <div class="title">AdonisJS {props.version} x Inertia x Solid.js</div>
13
+
14
+ <span>
15
+ Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
+ <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
17
+ </span>
18
+ </div>
19
+ </>
20
+ )
21
+ }
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/root.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x SolidJS</title>
12
+
13
+ @vite(['resources/app.tsx'])
14
+ @inertiaHead()
15
+ </head>
16
+
17
+ <body>
18
+ @inertia()
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,26 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "compilerOptions": {
6
+ "target": "ESNext",
7
+ "jsx": "preserve",
8
+ "jsxImportSource": "solid-js",
9
+ "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
10
+ "useDefineForClassFields": true,
11
+ "baseUrl": ".",
12
+ "module": "ESNext",
13
+ "moduleResolution": "Bundler",
14
+ "paths": {
15
+ "@/*": ["./*"],
16
+ "~/*": ["../*"],
17
+ },
18
+ "resolveJsonModule": true,
19
+ "types": ["vite/client"],
20
+ "allowSyntheticDefaultImports": true,
21
+ "esModuleInterop": true,
22
+ "verbatimModuleSyntax": true,
23
+ "skipLibCheck": true,
24
+ },
25
+ "include": ["./**/*.ts", "./**/*.tsx", "app.tsx.stub"],
26
+ }
@@ -1,5 +1,7 @@
1
+ import { Vite } from '@adonisjs/vite';
1
2
  import { HttpContext } from '@adonisjs/core/http';
2
3
  import { NextFn } from '@adonisjs/core/types/http';
4
+ import { ViteRuntime } from 'vite/runtime';
3
5
  import { ResolvedConfig, Data, PageProps, MaybePromise } from './types.js';
4
6
 
5
7
  /**
@@ -13,7 +15,8 @@ declare class Inertia {
13
15
  #private;
14
16
  protected ctx: HttpContext;
15
17
  protected config: ResolvedConfig;
16
- constructor(ctx: HttpContext, config: ResolvedConfig);
18
+ protected viteRuntime?: ViteRuntime | undefined;
19
+ constructor(ctx: HttpContext, config: ResolvedConfig, viteRuntime?: ViteRuntime | undefined);
17
20
  /**
18
21
  * Share data for the current request.
19
22
  * This data will override any shared data defined in the config.
@@ -61,8 +64,9 @@ declare module '@adonisjs/core/http' {
61
64
  * set appropriate headers/status
62
65
  */
63
66
  declare class InertiaMiddleware {
67
+ #private;
64
68
  protected config: ResolvedConfig;
65
- constructor(config: ResolvedConfig);
69
+ constructor(config: ResolvedConfig, vite?: Vite);
66
70
  handle(ctx: HttpContext, next: NextFn): Promise<void>;
67
71
  }
68
72
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-RXGBTZMN.js";
3
+ } from "../chunk-CXICUKHN.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import { PluginFn } from '@japa/runner/types';
2
- import { PageProps } from '../types.js';
3
2
  import { ApplicationService } from '@adonisjs/core/types';
3
+ import { PageProps } from '../../types.js';
4
4
  import '@adonisjs/core/http';
5
5
 
6
6
  declare module '@japa/api-client' {
@@ -1,4 +1,4 @@
1
- // src/plugins/api_client.ts
1
+ // src/plugins/japa/api_client.ts
2
2
  import { configProvider } from "@adonisjs/core";
3
3
  import { RuntimeException } from "@poppinss/utils";
4
4
  import { ApiRequest, ApiResponse } from "@japa/api-client";
@@ -0,0 +1,26 @@
1
+ import { PluginOption } from 'vite';
2
+
3
+ type InertiaPluginOptions = {
4
+ ssr?: {
5
+ /**
6
+ * Whether or not to enable server-side rendering
7
+ */
8
+ enabled: true;
9
+ /**
10
+ * The entrypoint for the server-side rendering
11
+ */
12
+ entrypoint: string;
13
+ /**
14
+ * The output directory for the server-side rendering bundle
15
+ */
16
+ output?: string;
17
+ } | {
18
+ enabled: false;
19
+ };
20
+ };
21
+ /**
22
+ * Inertia plugin for Vite that is tailored for AdonisJS
23
+ */
24
+ declare function inertia(options: InertiaPluginOptions): PluginOption;
25
+
26
+ export { type InertiaPluginOptions, inertia as default };
@@ -0,0 +1,33 @@
1
+ // src/plugins/vite.ts
2
+ function inertia(options) {
3
+ return {
4
+ name: "vite-plugin-inertia",
5
+ config: () => {
6
+ if (!options.ssr?.enabled)
7
+ return {};
8
+ return {
9
+ buildSteps: [
10
+ {
11
+ name: "build-client",
12
+ description: "build inertia client bundle",
13
+ config: { build: { outDir: "build/public/assets/" } }
14
+ },
15
+ {
16
+ name: "build-ssr",
17
+ description: "build inertia server bundle",
18
+ config: {
19
+ build: {
20
+ ssr: true,
21
+ outDir: options.ssr.output || "build/ssr",
22
+ rollupOptions: { input: options.ssr.entrypoint }
23
+ }
24
+ }
25
+ }
26
+ ]
27
+ };
28
+ }
29
+ };
30
+ }
31
+ export {
32
+ inertia as default
33
+ };
@@ -56,6 +56,27 @@ interface InertiaConfig {
56
56
  * Data that should be shared with all rendered pages
57
57
  */
58
58
  sharedData?: SharedData;
59
+ /**
60
+ * Options to configure SSR
61
+ */
62
+ ssr?: {
63
+ /**
64
+ * Enable or disable SSR
65
+ */
66
+ enabled: boolean;
67
+ /**
68
+ * List of components that should be rendered on the server
69
+ */
70
+ pages?: string[];
71
+ /**
72
+ * Path to the SSR entrypoint file
73
+ */
74
+ entrypoint?: string;
75
+ /**
76
+ * Path to the SSR bundled file that will be used in production
77
+ */
78
+ bundle?: string;
79
+ };
59
80
  }
60
81
  /**
61
82
  * Resolved inertia configuration
@@ -64,6 +85,12 @@ interface ResolvedConfig {
64
85
  rootView: string;
65
86
  versionCache: VersionCache;
66
87
  sharedData: SharedData;
88
+ ssr: {
89
+ enabled: boolean;
90
+ entrypoint: string;
91
+ pages?: string[];
92
+ bundle: string;
93
+ };
67
94
  }
68
95
 
69
96
  export type { AssetsVersion, Data, InertiaConfig, MaybePromise, PageProps, ResolvedConfig, SharedData, SharedDatumFactory };
@@ -0,0 +1,27 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.ts') })
3
+ }}}
4
+ import './css/app.css';
5
+
6
+ import { createApp, h } from 'vue'
7
+ import type { DefineComponent } from 'vue'
8
+ import { createInertiaApp } from '@inertiajs/vue3'
9
+
10
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
11
+
12
+ createInertiaApp({
13
+ progress: { color: '#5468FF' },
14
+
15
+ title: (title) => {{ '`${title} - ${appName}`' }},
16
+
17
+ resolve: (name) => {
18
+ const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
19
+ {{ 'return pages[`./pages/${name}.vue`]' }}
20
+ },
21
+
22
+ setup({ el, App, props, plugin }) {
23
+ createApp({ render: () => h(App, props) })
24
+ .use(plugin)
25
+ .mount(el)
26
+ },
27
+ })
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.vue') })
3
+ }}}
4
+ <script setup lang="ts">
5
+ import { Head } from '@inertiajs/vue3'
6
+
7
+ defineProps<{ version: number }>()
8
+ </script>
9
+
10
+ <template>
11
+ <Head title="Homepage" />
12
+
13
+ <div className="container">
14
+ <div className="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
15
+
16
+ <span>
17
+ Learn more about AdonisJS and Inertia.js by visiting the
18
+ <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
19
+ </span>
20
+ </div>
21
+ </template>
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/root.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x VueJS</title>
12
+
13
+ @vite(['resources/app.ts'])
14
+ @inertiaHead()
15
+ </head>
16
+
17
+ <body>
18
+ @inertia()
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,26 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "compilerOptions": {
6
+ "target": "ESNext",
7
+ "jsx": "preserve",
8
+ "jsxImportSource": "vue",
9
+ "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
10
+ "useDefineForClassFields": true,
11
+ "baseUrl": ".",
12
+ "module": "ESNext",
13
+ "moduleResolution": "Bundler",
14
+ "paths": {
15
+ "@/*": ["./*"],
16
+ "~/*": ["../*"],
17
+ },
18
+ "resolveJsonModule": true,
19
+ "types": ["vite/client"],
20
+ "allowSyntheticDefaultImports": true,
21
+ "esModuleInterop": true,
22
+ "verbatimModuleSyntax": true,
23
+ "skipLibCheck": true,
24
+ },
25
+ "include": ["./**/*.ts", "./**/*.vue"],
26
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "1.0.0-7",
4
+ "version": "1.0.0-8",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -17,7 +17,8 @@
17
17
  "./inertia_middleware": "./build/src/inertia_middleware.js",
18
18
  "./inertia_provider": "./build/providers/inertia_provider.js",
19
19
  "./plugins/edge": "./build/src/plugins/edge/plugin.js",
20
- "./plugins/api_client": "./build/src/plugins/api_client.js"
20
+ "./plugins/api_client": "./build/src/plugins/japa/api_client.js",
21
+ "./client": "./build/src/plugins/vite.js"
21
22
  },
22
23
  "scripts": {
23
24
  "clean": "del-cli build",
@@ -36,39 +37,42 @@
36
37
  "prepublishOnly": "npm run build"
37
38
  },
38
39
  "devDependencies": {
39
- "@adonisjs/assembler": "^7.0.0",
40
- "@adonisjs/core": "6.2.0",
40
+ "@adonisjs/assembler": "^7.2.1",
41
+ "@adonisjs/core": "6.3.0",
41
42
  "@adonisjs/eslint-config": "^1.2.1",
42
43
  "@adonisjs/prettier-config": "^1.2.1",
43
- "@adonisjs/session": "7.0.0",
44
+ "@adonisjs/session": "7.1.1",
44
45
  "@adonisjs/tsconfig": "^1.2.1",
46
+ "@adonisjs/vite": "^3.0.0-0",
45
47
  "@japa/api-client": "^2.0.2",
46
48
  "@japa/assert": "2.1.0",
47
49
  "@japa/expect-type": "^2.0.1",
48
- "@japa/file-system": "^2.1.1",
49
- "@japa/plugin-adonisjs": "^2.0.2",
50
+ "@japa/file-system": "^2.2.0",
51
+ "@japa/plugin-adonisjs": "^2.0.3",
50
52
  "@japa/runner": "3.1.1",
51
- "@swc/core": "^1.3.102",
52
- "@types/node": "^20.10.8",
53
+ "@swc/core": "^1.4.2",
54
+ "@types/node": "^20.11.20",
53
55
  "@types/qs": "^6.9.11",
54
56
  "@types/supertest": "^6.0.2",
55
- "c8": "^9.0.0",
57
+ "@vavite/multibuild": "^4.1.1",
58
+ "c8": "^9.1.0",
56
59
  "copyfiles": "^2.4.1",
57
60
  "del-cli": "^5.1.0",
58
61
  "edge-parser": "^9.0.1",
59
62
  "edge.js": "^6.0.1",
60
- "eslint": "^8.56.0",
63
+ "eslint": "^8.57.0",
61
64
  "get-port": "^7.0.0",
62
65
  "np": "^9.2.0",
63
- "prettier": "^3.1.1",
64
- "supertest": "^6.3.3",
65
- "tinybench": "^2.5.1",
66
+ "prettier": "^3.2.5",
67
+ "supertest": "^6.3.4",
68
+ "tinybench": "^2.6.0",
66
69
  "ts-node": "^10.9.2",
67
- "tsup": "^8.0.1",
68
- "typescript": "~5.3.3"
70
+ "tsup": "^8.0.2",
71
+ "typescript": "~5.3.3",
72
+ "vite": "^5.1.4"
69
73
  },
70
74
  "dependencies": {
71
- "@poppinss/utils": "^6.7.0",
75
+ "@poppinss/utils": "^6.7.2",
72
76
  "crc-32": "^1.2.2",
73
77
  "edge-error": "^4.0.1",
74
78
  "html-entities": "^2.4.0",
@@ -77,6 +81,7 @@
77
81
  "peerDependencies": {
78
82
  "@adonisjs/core": "^6.2.0",
79
83
  "@adonisjs/session": "^7.0.0",
84
+ "@adonisjs/vite": "^3.0.0",
80
85
  "@japa/api-client": "^2.0.0",
81
86
  "edge.js": "^6.0.0"
82
87
  },
@@ -123,7 +128,8 @@
123
128
  "./src/inertia_middleware.ts",
124
129
  "./providers/inertia_provider.ts",
125
130
  "./src/plugins/edge/plugin.ts",
126
- "./src/plugins/api_client.ts"
131
+ "./src/plugins/japa/api_client.ts",
132
+ "./src/plugins/vite.ts"
127
133
  ],
128
134
  "outDir": "./build",
129
135
  "clean": true,