tonka-vite-plugin 1.32.5 → 1.32.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +76 -19
- package/package.json +2 -1
- package/types/index.d.ts +33 -4
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,43 +1,100 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
export default function tonkaPlugin(options = {}) {
|
|
3
4
|
const root = process.cwd();
|
|
5
|
+
const publicDir = options.publicDirectory
|
|
6
|
+
? path.resolve(root, options.publicDirectory)
|
|
7
|
+
: path.resolve(root, 'public');
|
|
8
|
+
const hotFile = path.resolve(publicDir, 'hot');
|
|
9
|
+
const refreshPaths = options.refresh === true
|
|
10
|
+
? ['resources/js/**']
|
|
11
|
+
: Array.isArray(options.refresh)
|
|
12
|
+
? options.refresh
|
|
13
|
+
: typeof options.refresh === 'string'
|
|
14
|
+
? [options.refresh]
|
|
15
|
+
: [];
|
|
16
|
+
let viteDevServerUrl;
|
|
17
|
+
let resolvedConfig;
|
|
4
18
|
return {
|
|
5
19
|
name: 'tonka-vite-plugin',
|
|
6
|
-
config
|
|
20
|
+
config(userConfig, { command, mode }) {
|
|
7
21
|
const input = options.input || {
|
|
8
|
-
'resources/css/app.css'
|
|
9
|
-
'resources/js/app.tsx'
|
|
22
|
+
app: 'resources/css/app.css',
|
|
23
|
+
main: 'resources/js/app.tsx',
|
|
10
24
|
};
|
|
11
25
|
const outDir = options.outDir || path.resolve(root, 'public/build');
|
|
12
26
|
const manifest = options.manifest !== false ? 'manifest.json' : false;
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
resolvedConfig = {
|
|
28
|
+
base: command === 'build'
|
|
29
|
+
? (options.buildBase ?? '/build/')
|
|
30
|
+
: '',
|
|
15
31
|
build: {
|
|
16
|
-
outDir
|
|
17
|
-
manifest
|
|
32
|
+
outDir,
|
|
33
|
+
manifest,
|
|
18
34
|
assetsDir: options.assetsDir || 'assets',
|
|
19
|
-
rollupOptions: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ssr: ssrBuild,
|
|
23
|
-
sourcemap: command === 'serve',
|
|
35
|
+
rollupOptions: { input },
|
|
36
|
+
ssr: options.ssr || false,
|
|
37
|
+
sourcemap: command === 'serve' ? true : (options.sourcemap ?? false),
|
|
24
38
|
copyPublicDir: false,
|
|
39
|
+
emptyOutDir: command === 'build',
|
|
25
40
|
},
|
|
26
41
|
resolve: {
|
|
27
|
-
alias:
|
|
28
|
-
'@': path.resolve(root, '
|
|
42
|
+
alias: {
|
|
43
|
+
'@': path.resolve(root, 'resources/js'),
|
|
44
|
+
...(options.alias || {}),
|
|
29
45
|
},
|
|
30
46
|
},
|
|
31
47
|
optimizeDeps: {
|
|
32
|
-
include: ['react', 'react-dom', '@inertiajs/react'
|
|
48
|
+
include: ['react', 'react-dom', '@inertiajs/react'],
|
|
33
49
|
exclude: [],
|
|
34
50
|
},
|
|
51
|
+
server: {
|
|
52
|
+
origin: userConfig.server?.origin,
|
|
53
|
+
cors: true,
|
|
54
|
+
watch: {
|
|
55
|
+
ignored: [
|
|
56
|
+
'**/public/build/**',
|
|
57
|
+
'**/public/hot',
|
|
58
|
+
'**/node_modules/**',
|
|
59
|
+
'**/vendor/**',
|
|
60
|
+
...['ap', 'routes', 'bootstrap', 'database', 'config', 'test'].map((dir) => path.resolve(root, dir) + '/**'),
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
35
64
|
};
|
|
65
|
+
return resolvedConfig;
|
|
36
66
|
},
|
|
37
|
-
|
|
38
|
-
|
|
67
|
+
configureServer(server) {
|
|
68
|
+
const cleanupHotFile = () => {
|
|
69
|
+
if (fs.existsSync(hotFile))
|
|
70
|
+
fs.rmSync(hotFile);
|
|
71
|
+
};
|
|
72
|
+
cleanupHotFile();
|
|
73
|
+
server.httpServer?.once('listening', () => {
|
|
74
|
+
const address = server.httpServer?.address();
|
|
75
|
+
const protocol = server.config.server.https ? 'https' : 'http';
|
|
76
|
+
if (address && typeof address === 'object') {
|
|
77
|
+
viteDevServerUrl =
|
|
78
|
+
resolvedConfig.server?.origin ??
|
|
79
|
+
`${protocol}://${address.address === '::' ? 'localhost' : address.address}:${address.port}`;
|
|
80
|
+
fs.mkdirSync(publicDir, { recursive: true });
|
|
81
|
+
fs.writeFileSync(hotFile, viteDevServerUrl);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const exitHandler = () => cleanupHotFile();
|
|
85
|
+
process.on('exit', exitHandler);
|
|
86
|
+
process.on('SIGINT', () => process.exit());
|
|
87
|
+
process.on('SIGTERM', () => process.exit());
|
|
88
|
+
server.httpServer?.once('close', cleanupHotFile);
|
|
89
|
+
if (refreshPaths.length > 0) {
|
|
90
|
+
const watcher = server.watcher.add(refreshPaths);
|
|
91
|
+
watcher.on('change', (file) => {
|
|
92
|
+
server.ws.send({ type: 'full-reload', path: '*' });
|
|
93
|
+
});
|
|
39
94
|
}
|
|
40
|
-
|
|
95
|
+
},
|
|
96
|
+
transformIndexHtml() {
|
|
97
|
+
return undefined;
|
|
41
98
|
},
|
|
42
99
|
};
|
|
43
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tonka-vite-plugin",
|
|
3
|
-
"version": "1.32.
|
|
3
|
+
"version": "1.32.8",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "A Vite plugin for Inertia.js that provides automatic page imports and enhanced development experience.",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
package/types/index.d.ts
CHANGED
|
@@ -16,10 +16,17 @@ export interface TonkaPluginOptions {
|
|
|
16
16
|
ssr?: string | false;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Whether to
|
|
20
|
-
*
|
|
19
|
+
* Whether to watch server-rendered files (views, routes, PHP, ...) and
|
|
20
|
+
* trigger a full browser reload when they change, since Vite's module
|
|
21
|
+
* graph can't HMR server-rendered templates.
|
|
22
|
+
*
|
|
23
|
+
* - `true` → watch a sensible default set (`resources/views/**`,
|
|
24
|
+
* `app/**\/*.php`, `routes/**`)
|
|
25
|
+
* - string → a single glob pattern to watch
|
|
26
|
+
* - string[] → an explicit list of glob patterns to watch
|
|
27
|
+
* - false → disabled (default)
|
|
21
28
|
*/
|
|
22
|
-
refresh?: boolean;
|
|
29
|
+
refresh?: boolean | string | string[];
|
|
23
30
|
|
|
24
31
|
/**
|
|
25
32
|
* The output directory for the production build.
|
|
@@ -34,12 +41,34 @@ export interface TonkaPluginOptions {
|
|
|
34
41
|
|
|
35
42
|
/**
|
|
36
43
|
* Path aliases (e.g., '@' to point to the root or resources).
|
|
44
|
+
* Merged with the plugin's default alias ('@' -> 'resources/js').
|
|
37
45
|
*/
|
|
38
46
|
alias?: Record<string, string>;
|
|
39
|
-
|
|
47
|
+
|
|
40
48
|
/**
|
|
41
49
|
* Whether to generate a manifest.json file.
|
|
42
50
|
* Defaults to true for production.
|
|
43
51
|
*/
|
|
44
52
|
manifest?: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The public directory of the project, used to locate/write the `hot`
|
|
56
|
+
* file that signals the dev server's URL to the backend.
|
|
57
|
+
* Defaults to 'public'.
|
|
58
|
+
*/
|
|
59
|
+
publicDirectory?: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The `base` path used for built asset URLs in production
|
|
63
|
+
* (i.e. what the backend should prefix asset paths with).
|
|
64
|
+
* Defaults to '/build/'.
|
|
65
|
+
*/
|
|
66
|
+
buildBase?: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether to emit sourcemaps for the production build.
|
|
70
|
+
* Dev builds always emit sourcemaps regardless of this setting.
|
|
71
|
+
* Defaults to false.
|
|
72
|
+
*/
|
|
73
|
+
sourcemap?: boolean;
|
|
45
74
|
}
|