tonka-vite-plugin 1.21.0 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,10 +14,9 @@ This plugin automates the configuration of Vite for applications using **Inertia
14
14
 
15
15
  ## 📦 Installation
16
16
 
17
- Since this is a local plugin specific to your Tonka setup, copy the plugin file into your project root.
18
-
19
- 1. Create a file named `tonka-vite-plugin.ts` (or `.js`) in your project root.
20
- 2. Paste the code provided in the documentation into this file.
17
+ ```bash
18
+ npm i tonka-vite-plugin
19
+ ```
21
20
 
22
21
  ## 🚀 Quick Start
23
22
 
@@ -26,7 +25,7 @@ Import the plugin into your `vite.config.ts` to activate it.
26
25
  ```typescript
27
26
  import { defineConfig } from 'vite';
28
27
  import react from '@vitejs/plugin-react';
29
- import tonka from './tonka-vite-plugin';
28
+ import tonka from 'tonka-vite-plugin';
30
29
 
31
30
  export default defineConfig({
32
31
  plugins: [
@@ -68,14 +67,14 @@ When you run `npm run build`, the plugin automatically configures Rollup (the bu
68
67
  If you provide an `ssr` entry point, the plugin configures Vite to perform a second build specifically for the server. This allows your backend (Tonka) to render the initial page state on the server for faster load times and SEO.
69
68
 
70
69
  ### 3. Integration with Backend
71
- The plugin prepares the assets, but the **injection** of the `<script>` tags into the HTML is handled by your backend (Tonka) via the `@vite` Blade directive. This ensures that the correct script source is used:
70
+ The plugin prepares the assets, but the **injection** of the `<script>` tags into the HTML is handled by your backend (Tonka) via the `@vite` directive. This ensures that the correct script source is used:
72
71
  * **Dev**: Points to `http://localhost:5173/@vite/client` (for HMR).
73
72
  * **Prod**: Points to `/build/assets/xxxxx.js` (using the manifest).
74
73
 
75
74
  ## 🛠️ Development vs Production
76
75
 
77
76
  **In Development:**
78
- The plugin ensures the dev server runs on port 5173 and resolves aliases correctly. It relies on the backend to proxy requests or inject the client script.
77
+ The plugin ensures the dev server runs on port `5173` (or the one you specify for vite) and resolves aliases correctly. It relies on the backend to proxy requests or inject the client script.
79
78
 
80
79
  **In Production:**
81
80
  The plugin is essential to correctly generate the `manifest.json`. Without this plugin generating the manifest, your backend would fail to locate the compiled `.js` files after a build.
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import { TonkaPluginOptions } from '../types';
3
+ export default function tonkaPlugin(options?: TonkaPluginOptions): Plugin;
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import path from 'path';
2
+ export default function tonkaPlugin(options = {}) {
3
+ const root = process.cwd();
4
+ return {
5
+ name: 'tonka-vite-plugin',
6
+ config: (userConfig, { command }) => {
7
+ const input = options.input || {
8
+ 'resources/css/app.css': undefined,
9
+ 'resources/js/app.tsx': undefined,
10
+ };
11
+ const outDir = options.outDir || path.resolve(root, 'public/build');
12
+ const manifest = options.manifest !== false ? 'manifest.json' : false;
13
+ const ssrBuild = options.ssr ? options.ssr : false;
14
+ return {
15
+ build: {
16
+ outDir: outDir,
17
+ manifest: manifest,
18
+ assetsDir: options.assetsDir || 'assets',
19
+ rollupOptions: {
20
+ input: input,
21
+ },
22
+ ssr: ssrBuild,
23
+ sourcemap: command === 'serve',
24
+ },
25
+ resolve: {
26
+ alias: options.alias || {
27
+ '@': path.resolve(root, '.'),
28
+ },
29
+ },
30
+ optimizeDeps: {
31
+ include: ['react', 'react-dom', '@inertiajs/react', 'axios'],
32
+ exclude: [],
33
+ },
34
+ };
35
+ },
36
+ transformIndexHtml(html) {
37
+ if (options.refresh) {
38
+ }
39
+ return html;
40
+ },
41
+ };
42
+ }
package/package.json CHANGED
@@ -1,10 +1,22 @@
1
1
  {
2
2
  "name": "tonka-vite-plugin",
3
- "version": "1.21.0",
3
+ "version": "1.31.0",
4
4
  "description": "A Vite plugin for Inertia.js that provides automatic page imports and enhanced development experience.",
5
- "main": "index.ts",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "types"
13
+ ],
6
14
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "build": "tsc"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.0.0",
19
+ "vite": "^5.0.0"
8
20
  },
9
21
  "repository": {
10
22
  "type": "git",
package/bin/index.ts DELETED
@@ -1,101 +0,0 @@
1
- import type { Plugin, UserConfig } from 'vite';
2
- import { fileURLToPath, URL } from 'node:url';
3
- import path from 'path';
4
- import { TonkaPluginOptions } from '../lib';
5
-
6
- /**
7
- * Tonka Vite Plugin
8
- *
9
- * A Vite plugin specifically designed for the Tonka Framework.
10
- * It automates the configuration for Inertia.js, SSR, and asset paths.
11
- *
12
- * @param options - Configuration options for the plugin
13
- * @returns A Vite plugin object
14
- */
15
- export default function tonkaPlugin(options: TonkaPluginOptions = {}): Plugin {
16
- // Determine the base directory of the project
17
- const root = process.cwd();
18
-
19
- return {
20
- name: 'tonka-vite-plugin',
21
-
22
- /**
23
- * The `config` hook is called before the user config is resolved.
24
- * We use it to inject default settings and handle the Tonka-specific structure.
25
- */
26
- config: (userConfig: UserConfig, { command }) => {
27
- // 1. Handle Inputs
28
- // If the user doesn't provide inputs, we assume the standard structure.
29
- // Note: We cast to 'any' here to satisfy Rollup's strict typing for input.
30
- const input: any = options.input || {
31
- 'resources/css/app.css': undefined, // CSS entry
32
- 'resources/js/app.tsx': undefined, // Main JS entry
33
- };
34
-
35
- // 2. Handle Output Directory
36
- // Default to 'public/build' if not specified
37
- const outDir = options.outDir || path.resolve(root, 'public/build');
38
-
39
- // 3. Handle Manifest
40
- // Ensure manifest is generated unless explicitly disabled
41
- const manifest = options.manifest !== false ? 'manifest.json' : false;
42
-
43
- // 4. Handle SSR
44
- // If ssr is false, we ensure we don't set the ssr config.
45
- const ssrBuild = options.ssr ? options.ssr : false;
46
-
47
- return {
48
- build: {
49
- outDir: outDir,
50
- manifest: manifest,
51
- assetsDir: options.assetsDir || 'assets',
52
-
53
- // Rollup options
54
- rollupOptions: {
55
- input: input,
56
- },
57
-
58
- // Server-Side Rendering configuration
59
- ssr: ssrBuild,
60
-
61
- // Source maps: enabled in dev, disabled in prod (optional optimization)
62
- sourcemap: command === 'serve',
63
- },
64
-
65
- // 5. Resolve Aliases
66
- resolve: {
67
- // Merge user aliases with defaults
68
- alias: options.alias || {
69
- // Default alias: '@' points to the root of the project
70
- // You can also point it to 'resources' or 'public' based on your preference.
71
- '@': path.resolve(root, '.'),
72
- },
73
- },
74
-
75
- // 6. Optimize dependencies
76
- // Pre-bundle common dependencies to speed up dev server start
77
- optimizeDeps: {
78
- include: ['react', 'react-dom', '@inertiajs/react', 'axios'],
79
- exclude: [],
80
- },
81
- };
82
- },
83
-
84
- /**
85
- * The `transformIndexHtml` hook allows modifying the HTML index file.
86
- * This can be used to inject the @vite/client script for HMR if needed.
87
- */
88
- transformIndexHtml(html) {
89
- // If refresh is enabled, we could inject the HMR client here.
90
- // However, in a typical Inertia setup (like Tonka), this is often
91
- // handled by the server-side Blade/PHP template (@vite directive).
92
- // We leave this placeholder for future enhancements.
93
- if (options.refresh) {
94
- // Implementation note: Injecting @vite/client usually requires
95
- // knowing the exact module path, which varies.
96
- // For now, we trust the server-side directive.
97
- }
98
- return html;
99
- },
100
- };
101
- }
package/index.ts DELETED
@@ -1,2 +0,0 @@
1
- import tonkaPlugin from './bin';
2
- export default tonkaPlugin;
File without changes