litestar-vite-plugin 0.1.7 → 0.2.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/dist/index.d.ts +9 -3
- package/package.json +6 -6
- package/dist/dev-server-index.html +0 -185
- package/dist/index.cjs +0 -426
- package/dist/index.mjs +0 -397
package/dist/index.d.ts
CHANGED
|
@@ -14,13 +14,19 @@ interface PluginConfig {
|
|
|
14
14
|
/**
|
|
15
15
|
* The public directory where all compiled/bundled assets should be written.
|
|
16
16
|
*
|
|
17
|
-
* @default 'public'
|
|
17
|
+
* @default 'public/dist'
|
|
18
18
|
*/
|
|
19
19
|
bundleDirectory?: string;
|
|
20
20
|
/**
|
|
21
|
-
* The directory
|
|
21
|
+
* The root directory for your project.
|
|
22
22
|
*
|
|
23
|
-
* @default '
|
|
23
|
+
* @default ''
|
|
24
|
+
*/
|
|
25
|
+
rootDirectory?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Litestar's public assets directory. These are the assets that Vite will serve when developing.
|
|
28
|
+
*
|
|
29
|
+
* @default '${rootDirectory}/resources'
|
|
24
30
|
*/
|
|
25
31
|
resourceDirectory?: string;
|
|
26
32
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litestar-vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Litestar plugin for Vite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"litestar",
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
"test": "vitest run"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/node": "
|
|
45
|
+
"@types/node": ">=18.11.9",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
|
47
47
|
"@typescript-eslint/parser": "^5.21.0",
|
|
48
48
|
"esbuild": "0.16.10",
|
|
49
49
|
"eslint": "^8.14.0",
|
|
50
50
|
"typescript": "^4.6.4",
|
|
51
|
-
"vite": "
|
|
52
|
-
"vitest": "
|
|
51
|
+
"vite": ">=4.0.0",
|
|
52
|
+
"vitest": ">=0.34.4"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"vite": "^3.0.0 || ^4.0.0"
|
|
55
|
+
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
58
|
+
"node": ">=18"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"picocolors": "^1.0.0",
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
|
|
7
|
-
<title>Litestar Vite</title>
|
|
8
|
-
|
|
9
|
-
<!-- Fonts -->
|
|
10
|
-
<link
|
|
11
|
-
href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap"
|
|
12
|
-
rel="stylesheet"
|
|
13
|
-
/>
|
|
14
|
-
|
|
15
|
-
<script src="https://cdn.tailwindcss.com"></script>
|
|
16
|
-
</head>
|
|
17
|
-
<body class="antialiased">
|
|
18
|
-
<div
|
|
19
|
-
class="relative flex min-h-screen flex-col justify-center overflow-hidden bg-gray-100 text-gray-600 dark:text-gray-400 dark:bg-gray-900 py-6 sm:py-12"
|
|
20
|
-
>
|
|
21
|
-
<div
|
|
22
|
-
class="relative bg-white dark:bg-gray-800 px-6 pt-10 pb-8 shadow-xl ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-xl sm:rounded-lg sm:px-10"
|
|
23
|
-
>
|
|
24
|
-
<div class="mx-auto">
|
|
25
|
-
<div class="flex items-center justify-center space-x-6">
|
|
26
|
-
<a href="https://litestar.dev">
|
|
27
|
-
<svg
|
|
28
|
-
viewBox="0 52 410 250"
|
|
29
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
30
|
-
class="h-16 w-auto"
|
|
31
|
-
>
|
|
32
|
-
<defs>
|
|
33
|
-
<clipPath id="9eb7762d41">
|
|
34
|
-
<path
|
|
35
|
-
d="M 15.933594 105 L 328 105 L 328 259 L 15.933594 259 Z M 15.933594 105 "
|
|
36
|
-
clip-rule="nonzero"
|
|
37
|
-
/>
|
|
38
|
-
</clipPath>
|
|
39
|
-
<clipPath id="183d3cc178">
|
|
40
|
-
<path
|
|
41
|
-
d="M 142 78.769531 L 359.433594 78.769531 L 359.433594 296.269531 L 142 296.269531 Z M 142 78.769531 "
|
|
42
|
-
clip-rule="nonzero"
|
|
43
|
-
/>
|
|
44
|
-
</clipPath>
|
|
45
|
-
</defs>
|
|
46
|
-
<g clip-path="url(#9eb7762d41)">
|
|
47
|
-
<path
|
|
48
|
-
fill="#edb641"
|
|
49
|
-
d="M 147.625 240.3125 C 161.5 233.984375 173.554688 227.011719 183.425781 220.550781 C 202.304688 208.203125 226.4375 185.242188 227.761719 183.410156 L 218.917969 177.503906 L 211.257812 172.386719 L 235.503906 171.441406 L 243.296875 171.136719 L 245.414062 163.640625 L 252.007812 140.304688 L 260.402344 163.054688 L 263.097656 170.363281 L 270.890625 170.058594 L 295.136719 169.113281 L 276.078125 184.117188 L 269.953125 188.9375 L 272.652344 196.25 L 281.046875 218.996094 L 260.871094 205.523438 L 254.390625 201.195312 L 248.265625 206.015625 L 229.207031 221.023438 L 232.480469 209.425781 L 235.796875 197.691406 L 236.207031 196.234375 C 213.003906 213.585938 180.546875 230.304688 161.140625 236.488281 C 156.6875 237.90625 152.183594 239.179688 147.625 240.3125 Z M 101.992188 258.078125 C 136.382812 256.734375 177.355469 248 217.675781 222.363281 L 209.90625 249.867188 L 254.910156 214.4375 L 302.539062 246.246094 L 282.71875 192.539062 L 327.71875 157.109375 L 270.46875 159.34375 L 250.648438 105.636719 L 235.085938 160.726562 L 177.835938 162.964844 L 210.980469 185.097656 C 189.164062 204.921875 134.445312 247.195312 61.957031 250.03125 C 47.300781 250.601562 31.914062 249.558594 15.933594 246.394531 C 15.933594 246.394531 52.011719 260.035156 101.992188 258.078125 "
|
|
50
|
-
fill-opacity="1"
|
|
51
|
-
fill-rule="nonzero"
|
|
52
|
-
/>
|
|
53
|
-
</g>
|
|
54
|
-
<g clip-path="url(#183d3cc178)">
|
|
55
|
-
<path
|
|
56
|
-
fill="#edb641"
|
|
57
|
-
d="M 250.789062 78.96875 C 190.78125 78.96875 142.140625 127.570312 142.140625 187.519531 C 142.140625 198.875 143.886719 209.816406 147.121094 220.101562 C 151.847656 217.75 156.363281 215.316406 160.660156 212.84375 C 158.394531 204.789062 157.183594 196.296875 157.183594 187.519531 C 157.183594 135.871094 199.089844 93.996094 250.789062 93.996094 C 302.484375 93.996094 344.390625 135.871094 344.390625 187.519531 C 344.390625 239.171875 302.484375 281.042969 250.789062 281.042969 C 222.75 281.042969 197.597656 268.722656 180.441406 249.210938 C 175.453125 251.152344 170.402344 252.917969 165.289062 254.511719 C 185.183594 279.816406 216.082031 296.070312 250.789062 296.070312 C 310.792969 296.070312 359.433594 247.472656 359.433594 187.519531 C 359.433594 127.570312 310.792969 78.96875 250.789062 78.96875 "
|
|
58
|
-
fill-opacity="1"
|
|
59
|
-
fill-rule="nonzero"
|
|
60
|
-
/>
|
|
61
|
-
</g>
|
|
62
|
-
<path
|
|
63
|
-
fill="#edb641"
|
|
64
|
-
d="M 92.292969 173.023438 L 98.289062 191.460938 L 117.691406 191.460938 L 101.992188 202.855469 L 107.988281 221.292969 L 92.292969 209.898438 L 76.59375 221.292969 L 82.589844 202.855469 L 66.894531 191.460938 L 86.296875 191.460938 L 92.292969 173.023438 "
|
|
65
|
-
fill-opacity="1"
|
|
66
|
-
fill-rule="nonzero"
|
|
67
|
-
/>
|
|
68
|
-
<path
|
|
69
|
-
fill="#edb641"
|
|
70
|
-
d="M 120.214844 112.25 L 125.390625 128.167969 L 142.140625 128.167969 L 128.589844 138 L 133.765625 153.917969 L 120.214844 144.082031 L 106.664062 153.917969 L 111.839844 138 L 98.289062 128.167969 L 115.039062 128.167969 L 120.214844 112.25 "
|
|
71
|
-
fill-opacity="1"
|
|
72
|
-
fill-rule="nonzero"
|
|
73
|
-
/>
|
|
74
|
-
<path
|
|
75
|
-
fill="#edb641"
|
|
76
|
-
d="M 34.695312 209.136719 L 37.71875 218.421875 L 47.492188 218.421875 L 39.585938 224.160156 L 42.605469 233.449219 L 34.695312 227.707031 L 26.792969 233.449219 L 29.8125 224.160156 L 21.90625 218.421875 L 31.679688 218.421875 L 34.695312 209.136719 "
|
|
77
|
-
fill-opacity="1"
|
|
78
|
-
fill-rule="nonzero"
|
|
79
|
-
/>
|
|
80
|
-
</svg>
|
|
81
|
-
</a>
|
|
82
|
-
<svg
|
|
83
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
84
|
-
class="h-6 w-6 text-gray-500"
|
|
85
|
-
fill="none"
|
|
86
|
-
viewBox="0 0 24 24"
|
|
87
|
-
stroke="currentColor"
|
|
88
|
-
stroke-width="2"
|
|
89
|
-
>
|
|
90
|
-
<path
|
|
91
|
-
stroke-linecap="round"
|
|
92
|
-
stroke-linejoin="round"
|
|
93
|
-
d="M12 4v16m8-8H4"
|
|
94
|
-
/>
|
|
95
|
-
</svg>
|
|
96
|
-
<a href="https://vitejs.dev">
|
|
97
|
-
<svg
|
|
98
|
-
viewBox="0 0 410 404"
|
|
99
|
-
fill="none"
|
|
100
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
101
|
-
class="h-16 w-auto"
|
|
102
|
-
>
|
|
103
|
-
<path
|
|
104
|
-
d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z"
|
|
105
|
-
fill="url(#paint0_linear)"
|
|
106
|
-
/>
|
|
107
|
-
<path
|
|
108
|
-
d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z"
|
|
109
|
-
fill="url(#paint1_linear)"
|
|
110
|
-
/>
|
|
111
|
-
<defs>
|
|
112
|
-
<linearGradient
|
|
113
|
-
id="paint0_linear"
|
|
114
|
-
x1="6.00017"
|
|
115
|
-
y1="32.9999"
|
|
116
|
-
x2="235"
|
|
117
|
-
y2="344"
|
|
118
|
-
gradientUnits="userSpaceOnUse"
|
|
119
|
-
>
|
|
120
|
-
<stop stop-color="#41D1FF" />
|
|
121
|
-
<stop offset="1" stop-color="#BD34FE" />
|
|
122
|
-
</linearGradient>
|
|
123
|
-
<linearGradient
|
|
124
|
-
id="paint1_linear"
|
|
125
|
-
x1="194.651"
|
|
126
|
-
y1="8.81818"
|
|
127
|
-
x2="236.076"
|
|
128
|
-
y2="292.989"
|
|
129
|
-
gradientUnits="userSpaceOnUse"
|
|
130
|
-
>
|
|
131
|
-
<stop stop-color="#FFEA83" />
|
|
132
|
-
<stop
|
|
133
|
-
offset="0.0833333"
|
|
134
|
-
stop-color="#FFDD35"
|
|
135
|
-
/>
|
|
136
|
-
<stop offset="1" stop-color="#FFA800" />
|
|
137
|
-
</linearGradient>
|
|
138
|
-
</defs>
|
|
139
|
-
</svg>
|
|
140
|
-
</a>
|
|
141
|
-
</div>
|
|
142
|
-
<div class="divide-y divide-gray-300 dark:divide-gray-700">
|
|
143
|
-
<div class="py-8 text-base leading-7">
|
|
144
|
-
<p>
|
|
145
|
-
This is the Vite development server that
|
|
146
|
-
provides Hot Module Replacement for your
|
|
147
|
-
Litestar application.
|
|
148
|
-
</p>
|
|
149
|
-
<p class="mt-6">
|
|
150
|
-
To access your Litestar application, you will
|
|
151
|
-
need to run a local development server.
|
|
152
|
-
</p>
|
|
153
|
-
</div>
|
|
154
|
-
<div class="pt-8 text-base leading-7">
|
|
155
|
-
<p>
|
|
156
|
-
Your Litestar application's configured
|
|
157
|
-
<code
|
|
158
|
-
class="text-sm font-bold text-gray-900 dark:text-gray-100"
|
|
159
|
-
>APP_URL</code
|
|
160
|
-
>
|
|
161
|
-
is:<br />
|
|
162
|
-
<a
|
|
163
|
-
href="{{ APP_URL }}"
|
|
164
|
-
class="font-semibold text-red-500 hover:text-red-600"
|
|
165
|
-
>{{ APP_URL }}</a
|
|
166
|
-
>
|
|
167
|
-
</p>
|
|
168
|
-
<p class="mt-6">
|
|
169
|
-
Want more information on Litestar's Vite
|
|
170
|
-
integration?
|
|
171
|
-
</p>
|
|
172
|
-
<p>
|
|
173
|
-
<a
|
|
174
|
-
href="https://litestar.dev/docs/vite"
|
|
175
|
-
class="font-semibold text-red-500 hover:text-red-600"
|
|
176
|
-
>Read the docs →</a
|
|
177
|
-
>
|
|
178
|
-
</p>
|
|
179
|
-
</div>
|
|
180
|
-
</div>
|
|
181
|
-
</div>
|
|
182
|
-
</div>
|
|
183
|
-
</div>
|
|
184
|
-
</body>
|
|
185
|
-
</html>
|
package/dist/index.cjs
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
var src_exports = {};
|
|
26
|
-
__export(src_exports, {
|
|
27
|
-
default: () => litestar,
|
|
28
|
-
refreshPaths: () => refreshPaths
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
var import_meta_url = typeof document === "undefined" ? new (require("url".replace("", ""))).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
32
|
-
var import_fs = __toESM(require("fs"));
|
|
33
|
-
var import_url = require("url");
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_picocolors = __toESM(require("picocolors"));
|
|
36
|
-
var import_vite = require("vite");
|
|
37
|
-
var import_vite_plugin_full_reload = __toESM(require("vite-plugin-full-reload"));
|
|
38
|
-
let exitHandlersBound = false;
|
|
39
|
-
const refreshPaths = [
|
|
40
|
-
"**/*.py",
|
|
41
|
-
"**/*.j2",
|
|
42
|
-
"**/*.html.j2",
|
|
43
|
-
"**/*.html",
|
|
44
|
-
"**/assets/**/*"
|
|
45
|
-
];
|
|
46
|
-
function litestar(config) {
|
|
47
|
-
const pluginConfig = resolvePluginConfig(config);
|
|
48
|
-
return [
|
|
49
|
-
resolveLitestarPlugin(pluginConfig),
|
|
50
|
-
...resolveFullReloadConfig(pluginConfig)
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
function resolveLitestarPlugin(pluginConfig) {
|
|
54
|
-
let viteDevServerUrl;
|
|
55
|
-
let resolvedConfig;
|
|
56
|
-
let userConfig;
|
|
57
|
-
const defaultAliases = {
|
|
58
|
-
"@": pluginConfig.resourceDirectory || "/resources/"
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
name: "litestar",
|
|
62
|
-
enforce: "post",
|
|
63
|
-
config: (config, { command, mode }) => {
|
|
64
|
-
userConfig = config;
|
|
65
|
-
const ssr = !!userConfig.build?.ssr;
|
|
66
|
-
const env = (0, import_vite.loadEnv)(mode, userConfig.envDir || process.cwd(), "");
|
|
67
|
-
const assetUrl = env.LITESTAR_ASSET_URL || pluginConfig.assetUrl;
|
|
68
|
-
const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
|
|
69
|
-
pluginConfig.detectTls
|
|
70
|
-
) ?? resolveEnvironmentServerConfig(env) : void 0;
|
|
71
|
-
ensureCommandShouldRunInEnvironment(command, env);
|
|
72
|
-
return {
|
|
73
|
-
base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : pluginConfig.assetUrl),
|
|
74
|
-
publicDir: userConfig.publicDir ?? false,
|
|
75
|
-
build: {
|
|
76
|
-
manifest: userConfig.build?.manifest ?? !ssr,
|
|
77
|
-
outDir: userConfig.build?.outDir ?? resolveOutDir(pluginConfig, ssr),
|
|
78
|
-
rollupOptions: {
|
|
79
|
-
input: userConfig.build?.rollupOptions?.input ?? resolveInput(pluginConfig, ssr)
|
|
80
|
-
},
|
|
81
|
-
assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0
|
|
82
|
-
},
|
|
83
|
-
server: {
|
|
84
|
-
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
85
|
-
...process.env.LITESTAR_VITE_ALLOW_REMOTE ? {
|
|
86
|
-
host: userConfig.server?.host ?? "0.0.0.0",
|
|
87
|
-
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
88
|
-
strictPort: userConfig.server?.strictPort ?? true
|
|
89
|
-
} : void 0,
|
|
90
|
-
...serverConfig ? {
|
|
91
|
-
host: userConfig.server?.host ?? serverConfig.host,
|
|
92
|
-
hmr: userConfig.server?.hmr === false ? false : {
|
|
93
|
-
...serverConfig.hmr,
|
|
94
|
-
...userConfig.server?.hmr === true ? {} : userConfig.server?.hmr
|
|
95
|
-
},
|
|
96
|
-
https: userConfig.server?.https === false ? false : {
|
|
97
|
-
...serverConfig.https,
|
|
98
|
-
...userConfig.server?.https === true ? {} : userConfig.server?.https
|
|
99
|
-
}
|
|
100
|
-
} : void 0
|
|
101
|
-
},
|
|
102
|
-
resolve: {
|
|
103
|
-
alias: Array.isArray(userConfig.resolve?.alias) ? [
|
|
104
|
-
...userConfig.resolve?.alias ?? [],
|
|
105
|
-
...Object.keys(defaultAliases).map((alias) => ({
|
|
106
|
-
find: alias,
|
|
107
|
-
replacement: defaultAliases[alias]
|
|
108
|
-
}))
|
|
109
|
-
] : {
|
|
110
|
-
...defaultAliases,
|
|
111
|
-
...userConfig.resolve?.alias
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
ssr: {
|
|
115
|
-
noExternal: noExternalInertiaHelpers(userConfig)
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
configResolved(config) {
|
|
120
|
-
resolvedConfig = config;
|
|
121
|
-
},
|
|
122
|
-
transform(code) {
|
|
123
|
-
if (resolvedConfig.command === "serve") {
|
|
124
|
-
code = code.replace(
|
|
125
|
-
/__litestar_vite_placeholder__/g,
|
|
126
|
-
viteDevServerUrl
|
|
127
|
-
);
|
|
128
|
-
return pluginConfig.transformOnServe(code, viteDevServerUrl);
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
configureServer(server) {
|
|
132
|
-
const envDir = resolvedConfig.envDir || process.cwd();
|
|
133
|
-
const appUrl = (0, import_vite.loadEnv)(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
134
|
-
server.httpServer?.once("listening", () => {
|
|
135
|
-
const address = server.httpServer?.address();
|
|
136
|
-
const isAddressInfo = (x) => typeof x === "object";
|
|
137
|
-
if (isAddressInfo(address)) {
|
|
138
|
-
viteDevServerUrl = resolveDevServerUrl(
|
|
139
|
-
address,
|
|
140
|
-
server.config,
|
|
141
|
-
userConfig
|
|
142
|
-
);
|
|
143
|
-
import_fs.default.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
|
|
144
|
-
setTimeout(() => {
|
|
145
|
-
server.config.logger.info(
|
|
146
|
-
`
|
|
147
|
-
${import_picocolors.default.red(
|
|
148
|
-
`${import_picocolors.default.bold(
|
|
149
|
-
"LITESTAR"
|
|
150
|
-
)} ${litestarVersion()}`
|
|
151
|
-
)} ${import_picocolors.default.dim("plugin")} ${import_picocolors.default.bold(
|
|
152
|
-
`v${pluginVersion()}`
|
|
153
|
-
)}`
|
|
154
|
-
);
|
|
155
|
-
server.config.logger.info("");
|
|
156
|
-
server.config.logger.info(
|
|
157
|
-
` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
158
|
-
"APP_URL"
|
|
159
|
-
)}: ${import_picocolors.default.cyan(
|
|
160
|
-
appUrl.replace(
|
|
161
|
-
/:(\d+)/,
|
|
162
|
-
(_, port) => `:${import_picocolors.default.bold(port)}`
|
|
163
|
-
)
|
|
164
|
-
)}`
|
|
165
|
-
);
|
|
166
|
-
}, 100);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (!exitHandlersBound) {
|
|
170
|
-
const clean = () => {
|
|
171
|
-
if (import_fs.default.existsSync(pluginConfig.hotFile)) {
|
|
172
|
-
import_fs.default.rmSync(pluginConfig.hotFile);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
process.on("exit", clean);
|
|
176
|
-
process.on("SIGINT", process.exit);
|
|
177
|
-
process.on("SIGTERM", process.exit);
|
|
178
|
-
process.on("SIGHUP", process.exit);
|
|
179
|
-
exitHandlersBound = true;
|
|
180
|
-
}
|
|
181
|
-
return () => server.middlewares.use((req, res, next) => {
|
|
182
|
-
if (req.url === "/index.html") {
|
|
183
|
-
res.statusCode = 404;
|
|
184
|
-
res.end(
|
|
185
|
-
import_fs.default.readFileSync(
|
|
186
|
-
import_path.default.join(
|
|
187
|
-
dirname(),
|
|
188
|
-
"dev-server-index.html"
|
|
189
|
-
)
|
|
190
|
-
).toString().replace(/{{ APP_URL }}/g, appUrl)
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
next();
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
199
|
-
if (command === "build" || env.LITESTAR_BYPASS_ENV_CHECK === "1") {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (typeof env.LITESTAR_MODE !== "undefined") {
|
|
203
|
-
throw Error(
|
|
204
|
-
"You should not run the Vite HMR server when Litestar is in production. You should build your assets for production instead. To disable this ENV check you may set LITESTAR_BYPASS_ENV_CHECK=1"
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (typeof env.CI !== "undefined") {
|
|
208
|
-
throw Error(
|
|
209
|
-
"You should not run the Vite HMR server in CI environments. You should build your assets for production instead. To disable this ENV check you may set LITESTAR_BYPASS_ENV_CHECK=1"
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function litestarVersion() {
|
|
214
|
-
return "";
|
|
215
|
-
}
|
|
216
|
-
function pluginVersion() {
|
|
217
|
-
try {
|
|
218
|
-
return JSON.parse(
|
|
219
|
-
import_fs.default.readFileSync(import_path.default.join(dirname(), "../package.json")).toString()
|
|
220
|
-
)?.version;
|
|
221
|
-
} catch {
|
|
222
|
-
return "";
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function resolvePluginConfig(config) {
|
|
226
|
-
if (typeof config === "undefined") {
|
|
227
|
-
throw new Error("litestar-vite-plugin: missing configuration.");
|
|
228
|
-
}
|
|
229
|
-
if (typeof config === "string" || Array.isArray(config)) {
|
|
230
|
-
config = { input: config, ssr: config };
|
|
231
|
-
}
|
|
232
|
-
if (typeof config.input === "undefined") {
|
|
233
|
-
throw new Error(
|
|
234
|
-
'litestar-vite-plugin: missing configuration for "input".'
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
if (typeof config.resourceDirectory === "string") {
|
|
238
|
-
config.resourceDirectory = config.resourceDirectory.trim().replace(/^\/+/, "");
|
|
239
|
-
if (config.resourceDirectory === "") {
|
|
240
|
-
throw new Error(
|
|
241
|
-
"litestar-vite-plugin: resourceDirectory must be a subdirectory. E.g. 'resources'."
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (typeof config.assetDirectory === "string") {
|
|
246
|
-
config.assetDirectory = config.assetDirectory.trim().replace(/^\/+/, "");
|
|
247
|
-
if (config.assetDirectory === "") {
|
|
248
|
-
throw new Error(
|
|
249
|
-
"litestar-vite-plugin: assetDirectory must be a subdirectory. E.g. 'assets'."
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if (typeof config.bundleDirectory === "string") {
|
|
254
|
-
config.bundleDirectory = config.bundleDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
255
|
-
if (config.bundleDirectory === "") {
|
|
256
|
-
throw new Error(
|
|
257
|
-
"litestar-vite-plugin: bundleDirectory must be a subdirectory. E.g. 'public'."
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (typeof config.ssrOutputDirectory === "string") {
|
|
262
|
-
config.ssrOutputDirectory = config.ssrOutputDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
263
|
-
}
|
|
264
|
-
if (config.refresh === true) {
|
|
265
|
-
config.refresh = [{ paths: refreshPaths }];
|
|
266
|
-
}
|
|
267
|
-
return {
|
|
268
|
-
input: config.input,
|
|
269
|
-
assetUrl: config.assetUrl || (config.assetUrl ?? "static"),
|
|
270
|
-
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
271
|
-
assetDirectory: config.assetDirectory ?? "assets",
|
|
272
|
-
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
273
|
-
ssr: config.ssr ?? config.input,
|
|
274
|
-
ssrOutputDirectory: config.ssrOutputDirectory ?? "bootstrap/ssr",
|
|
275
|
-
refresh: config.refresh ?? false,
|
|
276
|
-
hotFile: config.hotFile ?? import_path.default.join(config.assetDirectory ?? "hot"),
|
|
277
|
-
detectTls: config.detectTls ?? false,
|
|
278
|
-
transformOnServe: config.transformOnServe ?? ((code) => code)
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function resolveBase(config, assetUrl) {
|
|
282
|
-
return assetUrl + (config.assetUrl.endsWith("/") ? "" : "/");
|
|
283
|
-
}
|
|
284
|
-
function resolveInput(config, ssr) {
|
|
285
|
-
if (ssr) {
|
|
286
|
-
return config.ssr;
|
|
287
|
-
}
|
|
288
|
-
return config.input;
|
|
289
|
-
}
|
|
290
|
-
function resolveOutDir(config, ssr) {
|
|
291
|
-
if (ssr) {
|
|
292
|
-
return config.ssrOutputDirectory;
|
|
293
|
-
}
|
|
294
|
-
return import_path.default.join(config.bundleDirectory);
|
|
295
|
-
}
|
|
296
|
-
function resolveFullReloadConfig({
|
|
297
|
-
refresh: config
|
|
298
|
-
}) {
|
|
299
|
-
if (typeof config === "boolean") {
|
|
300
|
-
return [];
|
|
301
|
-
}
|
|
302
|
-
if (typeof config === "string") {
|
|
303
|
-
config = [{ paths: [config] }];
|
|
304
|
-
}
|
|
305
|
-
if (!Array.isArray(config)) {
|
|
306
|
-
config = [config];
|
|
307
|
-
}
|
|
308
|
-
if (config.some((c) => typeof c === "string")) {
|
|
309
|
-
config = [{ paths: config }];
|
|
310
|
-
}
|
|
311
|
-
return config.flatMap((c) => {
|
|
312
|
-
const plugin = (0, import_vite_plugin_full_reload.default)(c.paths, c.config);
|
|
313
|
-
plugin.__litestar_plugin_config = c;
|
|
314
|
-
return plugin;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
function resolveDevServerUrl(address, config, userConfig) {
|
|
318
|
-
const configHmrProtocol = typeof config.server.hmr === "object" ? config.server.hmr.protocol : null;
|
|
319
|
-
const clientProtocol = configHmrProtocol ? configHmrProtocol === "wss" ? "https" : "http" : null;
|
|
320
|
-
const serverProtocol = config.server.https ? "https" : "http";
|
|
321
|
-
const protocol = clientProtocol ?? serverProtocol;
|
|
322
|
-
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
323
|
-
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
324
|
-
const remoteHost = process.env.LITESTAR_VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
325
|
-
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
326
|
-
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
327
|
-
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
328
|
-
const port = configHmrClientPort ?? address.port;
|
|
329
|
-
return `${protocol}://${host}:${port}`;
|
|
330
|
-
}
|
|
331
|
-
function isIpv6(address) {
|
|
332
|
-
return address.family === "IPv6" || address.family === 6;
|
|
333
|
-
}
|
|
334
|
-
function noExternalInertiaHelpers(config) {
|
|
335
|
-
const userNoExternal = config.ssr?.noExternal;
|
|
336
|
-
const pluginNoExternal = ["litestar-vite-plugin"];
|
|
337
|
-
if (userNoExternal === true) {
|
|
338
|
-
return true;
|
|
339
|
-
}
|
|
340
|
-
if (typeof userNoExternal === "undefined") {
|
|
341
|
-
return pluginNoExternal;
|
|
342
|
-
}
|
|
343
|
-
return [
|
|
344
|
-
...Array.isArray(userNoExternal) ? userNoExternal : [userNoExternal],
|
|
345
|
-
...pluginNoExternal
|
|
346
|
-
];
|
|
347
|
-
}
|
|
348
|
-
function resolveEnvironmentServerConfig(env) {
|
|
349
|
-
if (!env.VITE_DEV_SERVER_KEY && !env.VITE_DEV_SERVER_CERT) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
if (!import_fs.default.existsSync(env.VITE_DEV_SERVER_KEY) || !import_fs.default.existsSync(env.VITE_DEV_SERVER_CERT)) {
|
|
353
|
-
throw Error(
|
|
354
|
-
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured VITE_DEV_SERVER_KEY: [${env.VITE_DEV_SERVER_KEY}] and VITE_DEV_SERVER_CERT: [${env.VITE_DEV_SERVER_CERT}].`
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
const host = resolveHostFromEnv(env);
|
|
358
|
-
if (!host) {
|
|
359
|
-
throw Error(
|
|
360
|
-
`Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
return {
|
|
364
|
-
hmr: { host },
|
|
365
|
-
host,
|
|
366
|
-
https: {
|
|
367
|
-
key: import_fs.default.readFileSync(env.VITE_DEV_SERVER_KEY),
|
|
368
|
-
cert: import_fs.default.readFileSync(env.VITE_DEV_SERVER_CERT)
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
function resolveHostFromEnv(env) {
|
|
373
|
-
try {
|
|
374
|
-
return new URL(env.APP_URL).host;
|
|
375
|
-
} catch {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
function resolveDevelopmentEnvironmentServerConfig(host) {
|
|
380
|
-
if (host === false) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
const configPath = determineDevelopmentEnvironmentConfigPath();
|
|
384
|
-
host = host === true ? resolveDevelopmentEnvironmentHost(configPath) : host;
|
|
385
|
-
const keyPath = import_path.default.resolve(configPath, "certs", `${host}.key`);
|
|
386
|
-
const certPath = import_path.default.resolve(configPath, "certs", `${host}.crt`);
|
|
387
|
-
if (!import_fs.default.existsSync(keyPath) || !import_fs.default.existsSync(certPath)) {
|
|
388
|
-
throw Error(
|
|
389
|
-
`Unable to find certificate files for your host [${host}] in the [${configPath}/certs] directory.`
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
return {
|
|
393
|
-
hmr: { host },
|
|
394
|
-
host,
|
|
395
|
-
https: {
|
|
396
|
-
key: import_fs.default.readFileSync(keyPath),
|
|
397
|
-
cert: import_fs.default.readFileSync(certPath)
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
function determineDevelopmentEnvironmentConfigPath() {
|
|
402
|
-
const envConfigPath = import_path.default.resolve(process.cwd(), ".config");
|
|
403
|
-
if (import_fs.default.existsSync(envConfigPath)) {
|
|
404
|
-
return envConfigPath;
|
|
405
|
-
}
|
|
406
|
-
return import_path.default.resolve(process.cwd(), ".config");
|
|
407
|
-
}
|
|
408
|
-
function resolveDevelopmentEnvironmentHost(configPath) {
|
|
409
|
-
const configFile = import_path.default.resolve(configPath, "config.json");
|
|
410
|
-
if (!import_fs.default.existsSync(configFile)) {
|
|
411
|
-
throw Error(
|
|
412
|
-
`Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
const config = JSON.parse(
|
|
416
|
-
import_fs.default.readFileSync(configFile, "utf-8")
|
|
417
|
-
);
|
|
418
|
-
return import_path.default.basename(process.cwd()) + "." + config.tld;
|
|
419
|
-
}
|
|
420
|
-
function dirname() {
|
|
421
|
-
return (0, import_url.fileURLToPath)(new URL(".", import_meta_url));
|
|
422
|
-
}
|
|
423
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
424
|
-
0 && (module.exports = {
|
|
425
|
-
refreshPaths
|
|
426
|
-
});
|
package/dist/index.mjs
DELETED
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import colors from "picocolors";
|
|
5
|
-
import {
|
|
6
|
-
loadEnv
|
|
7
|
-
} from "vite";
|
|
8
|
-
import fullReload from "vite-plugin-full-reload";
|
|
9
|
-
let exitHandlersBound = false;
|
|
10
|
-
const refreshPaths = [
|
|
11
|
-
"**/*.py",
|
|
12
|
-
"**/*.j2",
|
|
13
|
-
"**/*.html.j2",
|
|
14
|
-
"**/*.html",
|
|
15
|
-
"**/assets/**/*"
|
|
16
|
-
];
|
|
17
|
-
function litestar(config) {
|
|
18
|
-
const pluginConfig = resolvePluginConfig(config);
|
|
19
|
-
return [
|
|
20
|
-
resolveLitestarPlugin(pluginConfig),
|
|
21
|
-
...resolveFullReloadConfig(pluginConfig)
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
function resolveLitestarPlugin(pluginConfig) {
|
|
25
|
-
let viteDevServerUrl;
|
|
26
|
-
let resolvedConfig;
|
|
27
|
-
let userConfig;
|
|
28
|
-
const defaultAliases = {
|
|
29
|
-
"@": pluginConfig.resourceDirectory || "/resources/"
|
|
30
|
-
};
|
|
31
|
-
return {
|
|
32
|
-
name: "litestar",
|
|
33
|
-
enforce: "post",
|
|
34
|
-
config: (config, { command, mode }) => {
|
|
35
|
-
userConfig = config;
|
|
36
|
-
const ssr = !!userConfig.build?.ssr;
|
|
37
|
-
const env = loadEnv(mode, userConfig.envDir || process.cwd(), "");
|
|
38
|
-
const assetUrl = env.LITESTAR_ASSET_URL || pluginConfig.assetUrl;
|
|
39
|
-
const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
|
|
40
|
-
pluginConfig.detectTls
|
|
41
|
-
) ?? resolveEnvironmentServerConfig(env) : void 0;
|
|
42
|
-
ensureCommandShouldRunInEnvironment(command, env);
|
|
43
|
-
return {
|
|
44
|
-
base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : pluginConfig.assetUrl),
|
|
45
|
-
publicDir: userConfig.publicDir ?? false,
|
|
46
|
-
build: {
|
|
47
|
-
manifest: userConfig.build?.manifest ?? !ssr,
|
|
48
|
-
outDir: userConfig.build?.outDir ?? resolveOutDir(pluginConfig, ssr),
|
|
49
|
-
rollupOptions: {
|
|
50
|
-
input: userConfig.build?.rollupOptions?.input ?? resolveInput(pluginConfig, ssr)
|
|
51
|
-
},
|
|
52
|
-
assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0
|
|
53
|
-
},
|
|
54
|
-
server: {
|
|
55
|
-
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
56
|
-
...process.env.LITESTAR_VITE_ALLOW_REMOTE ? {
|
|
57
|
-
host: userConfig.server?.host ?? "0.0.0.0",
|
|
58
|
-
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
59
|
-
strictPort: userConfig.server?.strictPort ?? true
|
|
60
|
-
} : void 0,
|
|
61
|
-
...serverConfig ? {
|
|
62
|
-
host: userConfig.server?.host ?? serverConfig.host,
|
|
63
|
-
hmr: userConfig.server?.hmr === false ? false : {
|
|
64
|
-
...serverConfig.hmr,
|
|
65
|
-
...userConfig.server?.hmr === true ? {} : userConfig.server?.hmr
|
|
66
|
-
},
|
|
67
|
-
https: userConfig.server?.https === false ? false : {
|
|
68
|
-
...serverConfig.https,
|
|
69
|
-
...userConfig.server?.https === true ? {} : userConfig.server?.https
|
|
70
|
-
}
|
|
71
|
-
} : void 0
|
|
72
|
-
},
|
|
73
|
-
resolve: {
|
|
74
|
-
alias: Array.isArray(userConfig.resolve?.alias) ? [
|
|
75
|
-
...userConfig.resolve?.alias ?? [],
|
|
76
|
-
...Object.keys(defaultAliases).map((alias) => ({
|
|
77
|
-
find: alias,
|
|
78
|
-
replacement: defaultAliases[alias]
|
|
79
|
-
}))
|
|
80
|
-
] : {
|
|
81
|
-
...defaultAliases,
|
|
82
|
-
...userConfig.resolve?.alias
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
ssr: {
|
|
86
|
-
noExternal: noExternalInertiaHelpers(userConfig)
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
configResolved(config) {
|
|
91
|
-
resolvedConfig = config;
|
|
92
|
-
},
|
|
93
|
-
transform(code) {
|
|
94
|
-
if (resolvedConfig.command === "serve") {
|
|
95
|
-
code = code.replace(
|
|
96
|
-
/__litestar_vite_placeholder__/g,
|
|
97
|
-
viteDevServerUrl
|
|
98
|
-
);
|
|
99
|
-
return pluginConfig.transformOnServe(code, viteDevServerUrl);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
configureServer(server) {
|
|
103
|
-
const envDir = resolvedConfig.envDir || process.cwd();
|
|
104
|
-
const appUrl = loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
105
|
-
server.httpServer?.once("listening", () => {
|
|
106
|
-
const address = server.httpServer?.address();
|
|
107
|
-
const isAddressInfo = (x) => typeof x === "object";
|
|
108
|
-
if (isAddressInfo(address)) {
|
|
109
|
-
viteDevServerUrl = resolveDevServerUrl(
|
|
110
|
-
address,
|
|
111
|
-
server.config,
|
|
112
|
-
userConfig
|
|
113
|
-
);
|
|
114
|
-
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
|
|
115
|
-
setTimeout(() => {
|
|
116
|
-
server.config.logger.info(
|
|
117
|
-
`
|
|
118
|
-
${colors.red(
|
|
119
|
-
`${colors.bold(
|
|
120
|
-
"LITESTAR"
|
|
121
|
-
)} ${litestarVersion()}`
|
|
122
|
-
)} ${colors.dim("plugin")} ${colors.bold(
|
|
123
|
-
`v${pluginVersion()}`
|
|
124
|
-
)}`
|
|
125
|
-
);
|
|
126
|
-
server.config.logger.info("");
|
|
127
|
-
server.config.logger.info(
|
|
128
|
-
` ${colors.green("\u279C")} ${colors.bold(
|
|
129
|
-
"APP_URL"
|
|
130
|
-
)}: ${colors.cyan(
|
|
131
|
-
appUrl.replace(
|
|
132
|
-
/:(\d+)/,
|
|
133
|
-
(_, port) => `:${colors.bold(port)}`
|
|
134
|
-
)
|
|
135
|
-
)}`
|
|
136
|
-
);
|
|
137
|
-
}, 100);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
if (!exitHandlersBound) {
|
|
141
|
-
const clean = () => {
|
|
142
|
-
if (fs.existsSync(pluginConfig.hotFile)) {
|
|
143
|
-
fs.rmSync(pluginConfig.hotFile);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
process.on("exit", clean);
|
|
147
|
-
process.on("SIGINT", process.exit);
|
|
148
|
-
process.on("SIGTERM", process.exit);
|
|
149
|
-
process.on("SIGHUP", process.exit);
|
|
150
|
-
exitHandlersBound = true;
|
|
151
|
-
}
|
|
152
|
-
return () => server.middlewares.use((req, res, next) => {
|
|
153
|
-
if (req.url === "/index.html") {
|
|
154
|
-
res.statusCode = 404;
|
|
155
|
-
res.end(
|
|
156
|
-
fs.readFileSync(
|
|
157
|
-
path.join(
|
|
158
|
-
dirname(),
|
|
159
|
-
"dev-server-index.html"
|
|
160
|
-
)
|
|
161
|
-
).toString().replace(/{{ APP_URL }}/g, appUrl)
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
next();
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
170
|
-
if (command === "build" || env.LITESTAR_BYPASS_ENV_CHECK === "1") {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (typeof env.LITESTAR_MODE !== "undefined") {
|
|
174
|
-
throw Error(
|
|
175
|
-
"You should not run the Vite HMR server when Litestar is in production. You should build your assets for production instead. To disable this ENV check you may set LITESTAR_BYPASS_ENV_CHECK=1"
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
if (typeof env.CI !== "undefined") {
|
|
179
|
-
throw Error(
|
|
180
|
-
"You should not run the Vite HMR server in CI environments. You should build your assets for production instead. To disable this ENV check you may set LITESTAR_BYPASS_ENV_CHECK=1"
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function litestarVersion() {
|
|
185
|
-
return "";
|
|
186
|
-
}
|
|
187
|
-
function pluginVersion() {
|
|
188
|
-
try {
|
|
189
|
-
return JSON.parse(
|
|
190
|
-
fs.readFileSync(path.join(dirname(), "../package.json")).toString()
|
|
191
|
-
)?.version;
|
|
192
|
-
} catch {
|
|
193
|
-
return "";
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function resolvePluginConfig(config) {
|
|
197
|
-
if (typeof config === "undefined") {
|
|
198
|
-
throw new Error("litestar-vite-plugin: missing configuration.");
|
|
199
|
-
}
|
|
200
|
-
if (typeof config === "string" || Array.isArray(config)) {
|
|
201
|
-
config = { input: config, ssr: config };
|
|
202
|
-
}
|
|
203
|
-
if (typeof config.input === "undefined") {
|
|
204
|
-
throw new Error(
|
|
205
|
-
'litestar-vite-plugin: missing configuration for "input".'
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
if (typeof config.resourceDirectory === "string") {
|
|
209
|
-
config.resourceDirectory = config.resourceDirectory.trim().replace(/^\/+/, "");
|
|
210
|
-
if (config.resourceDirectory === "") {
|
|
211
|
-
throw new Error(
|
|
212
|
-
"litestar-vite-plugin: resourceDirectory must be a subdirectory. E.g. 'resources'."
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (typeof config.assetDirectory === "string") {
|
|
217
|
-
config.assetDirectory = config.assetDirectory.trim().replace(/^\/+/, "");
|
|
218
|
-
if (config.assetDirectory === "") {
|
|
219
|
-
throw new Error(
|
|
220
|
-
"litestar-vite-plugin: assetDirectory must be a subdirectory. E.g. 'assets'."
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (typeof config.bundleDirectory === "string") {
|
|
225
|
-
config.bundleDirectory = config.bundleDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
226
|
-
if (config.bundleDirectory === "") {
|
|
227
|
-
throw new Error(
|
|
228
|
-
"litestar-vite-plugin: bundleDirectory must be a subdirectory. E.g. 'public'."
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (typeof config.ssrOutputDirectory === "string") {
|
|
233
|
-
config.ssrOutputDirectory = config.ssrOutputDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
234
|
-
}
|
|
235
|
-
if (config.refresh === true) {
|
|
236
|
-
config.refresh = [{ paths: refreshPaths }];
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
input: config.input,
|
|
240
|
-
assetUrl: config.assetUrl || (config.assetUrl ?? "static"),
|
|
241
|
-
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
242
|
-
assetDirectory: config.assetDirectory ?? "assets",
|
|
243
|
-
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
244
|
-
ssr: config.ssr ?? config.input,
|
|
245
|
-
ssrOutputDirectory: config.ssrOutputDirectory ?? "bootstrap/ssr",
|
|
246
|
-
refresh: config.refresh ?? false,
|
|
247
|
-
hotFile: config.hotFile ?? path.join(config.assetDirectory ?? "hot"),
|
|
248
|
-
detectTls: config.detectTls ?? false,
|
|
249
|
-
transformOnServe: config.transformOnServe ?? ((code) => code)
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function resolveBase(config, assetUrl) {
|
|
253
|
-
return assetUrl + (config.assetUrl.endsWith("/") ? "" : "/");
|
|
254
|
-
}
|
|
255
|
-
function resolveInput(config, ssr) {
|
|
256
|
-
if (ssr) {
|
|
257
|
-
return config.ssr;
|
|
258
|
-
}
|
|
259
|
-
return config.input;
|
|
260
|
-
}
|
|
261
|
-
function resolveOutDir(config, ssr) {
|
|
262
|
-
if (ssr) {
|
|
263
|
-
return config.ssrOutputDirectory;
|
|
264
|
-
}
|
|
265
|
-
return path.join(config.bundleDirectory);
|
|
266
|
-
}
|
|
267
|
-
function resolveFullReloadConfig({
|
|
268
|
-
refresh: config
|
|
269
|
-
}) {
|
|
270
|
-
if (typeof config === "boolean") {
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
if (typeof config === "string") {
|
|
274
|
-
config = [{ paths: [config] }];
|
|
275
|
-
}
|
|
276
|
-
if (!Array.isArray(config)) {
|
|
277
|
-
config = [config];
|
|
278
|
-
}
|
|
279
|
-
if (config.some((c) => typeof c === "string")) {
|
|
280
|
-
config = [{ paths: config }];
|
|
281
|
-
}
|
|
282
|
-
return config.flatMap((c) => {
|
|
283
|
-
const plugin = fullReload(c.paths, c.config);
|
|
284
|
-
plugin.__litestar_plugin_config = c;
|
|
285
|
-
return plugin;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
function resolveDevServerUrl(address, config, userConfig) {
|
|
289
|
-
const configHmrProtocol = typeof config.server.hmr === "object" ? config.server.hmr.protocol : null;
|
|
290
|
-
const clientProtocol = configHmrProtocol ? configHmrProtocol === "wss" ? "https" : "http" : null;
|
|
291
|
-
const serverProtocol = config.server.https ? "https" : "http";
|
|
292
|
-
const protocol = clientProtocol ?? serverProtocol;
|
|
293
|
-
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
294
|
-
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
295
|
-
const remoteHost = process.env.LITESTAR_VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
296
|
-
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
297
|
-
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
298
|
-
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
299
|
-
const port = configHmrClientPort ?? address.port;
|
|
300
|
-
return `${protocol}://${host}:${port}`;
|
|
301
|
-
}
|
|
302
|
-
function isIpv6(address) {
|
|
303
|
-
return address.family === "IPv6" || address.family === 6;
|
|
304
|
-
}
|
|
305
|
-
function noExternalInertiaHelpers(config) {
|
|
306
|
-
const userNoExternal = config.ssr?.noExternal;
|
|
307
|
-
const pluginNoExternal = ["litestar-vite-plugin"];
|
|
308
|
-
if (userNoExternal === true) {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
if (typeof userNoExternal === "undefined") {
|
|
312
|
-
return pluginNoExternal;
|
|
313
|
-
}
|
|
314
|
-
return [
|
|
315
|
-
...Array.isArray(userNoExternal) ? userNoExternal : [userNoExternal],
|
|
316
|
-
...pluginNoExternal
|
|
317
|
-
];
|
|
318
|
-
}
|
|
319
|
-
function resolveEnvironmentServerConfig(env) {
|
|
320
|
-
if (!env.VITE_DEV_SERVER_KEY && !env.VITE_DEV_SERVER_CERT) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (!fs.existsSync(env.VITE_DEV_SERVER_KEY) || !fs.existsSync(env.VITE_DEV_SERVER_CERT)) {
|
|
324
|
-
throw Error(
|
|
325
|
-
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured VITE_DEV_SERVER_KEY: [${env.VITE_DEV_SERVER_KEY}] and VITE_DEV_SERVER_CERT: [${env.VITE_DEV_SERVER_CERT}].`
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
const host = resolveHostFromEnv(env);
|
|
329
|
-
if (!host) {
|
|
330
|
-
throw Error(
|
|
331
|
-
`Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
return {
|
|
335
|
-
hmr: { host },
|
|
336
|
-
host,
|
|
337
|
-
https: {
|
|
338
|
-
key: fs.readFileSync(env.VITE_DEV_SERVER_KEY),
|
|
339
|
-
cert: fs.readFileSync(env.VITE_DEV_SERVER_CERT)
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function resolveHostFromEnv(env) {
|
|
344
|
-
try {
|
|
345
|
-
return new URL(env.APP_URL).host;
|
|
346
|
-
} catch {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
function resolveDevelopmentEnvironmentServerConfig(host) {
|
|
351
|
-
if (host === false) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
const configPath = determineDevelopmentEnvironmentConfigPath();
|
|
355
|
-
host = host === true ? resolveDevelopmentEnvironmentHost(configPath) : host;
|
|
356
|
-
const keyPath = path.resolve(configPath, "certs", `${host}.key`);
|
|
357
|
-
const certPath = path.resolve(configPath, "certs", `${host}.crt`);
|
|
358
|
-
if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) {
|
|
359
|
-
throw Error(
|
|
360
|
-
`Unable to find certificate files for your host [${host}] in the [${configPath}/certs] directory.`
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
return {
|
|
364
|
-
hmr: { host },
|
|
365
|
-
host,
|
|
366
|
-
https: {
|
|
367
|
-
key: fs.readFileSync(keyPath),
|
|
368
|
-
cert: fs.readFileSync(certPath)
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
function determineDevelopmentEnvironmentConfigPath() {
|
|
373
|
-
const envConfigPath = path.resolve(process.cwd(), ".config");
|
|
374
|
-
if (fs.existsSync(envConfigPath)) {
|
|
375
|
-
return envConfigPath;
|
|
376
|
-
}
|
|
377
|
-
return path.resolve(process.cwd(), ".config");
|
|
378
|
-
}
|
|
379
|
-
function resolveDevelopmentEnvironmentHost(configPath) {
|
|
380
|
-
const configFile = path.resolve(configPath, "config.json");
|
|
381
|
-
if (!fs.existsSync(configFile)) {
|
|
382
|
-
throw Error(
|
|
383
|
-
`Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
const config = JSON.parse(
|
|
387
|
-
fs.readFileSync(configFile, "utf-8")
|
|
388
|
-
);
|
|
389
|
-
return path.basename(process.cwd()) + "." + config.tld;
|
|
390
|
-
}
|
|
391
|
-
function dirname() {
|
|
392
|
-
return fileURLToPath(new URL(".", import.meta.url));
|
|
393
|
-
}
|
|
394
|
-
export {
|
|
395
|
-
litestar as default,
|
|
396
|
-
refreshPaths
|
|
397
|
-
};
|