litestar-vite-plugin 0.3.1 → 0.4.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.
- package/dist/index.cjs +13 -21
- package/dist/index.d.ts +0 -6
- package/dist/index.mjs +13 -21
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -64,7 +64,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
64
64
|
userConfig = config;
|
|
65
65
|
const ssr = !!userConfig.build?.ssr;
|
|
66
66
|
const env = (0, import_vite.loadEnv)(mode, userConfig.envDir || process.cwd(), "");
|
|
67
|
-
const assetUrl = env.
|
|
67
|
+
const assetUrl = env.ASSET_URL || pluginConfig.assetUrl;
|
|
68
68
|
const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
|
|
69
69
|
pluginConfig.detectTls
|
|
70
70
|
) ?? resolveEnvironmentServerConfig(env) : void 0;
|
|
@@ -82,7 +82,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
82
82
|
},
|
|
83
83
|
server: {
|
|
84
84
|
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
85
|
-
...process.env.
|
|
85
|
+
...process.env.VITE_ALLOW_REMOTE ? {
|
|
86
86
|
host: userConfig.server?.host ?? "0.0.0.0",
|
|
87
87
|
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
88
88
|
strictPort: userConfig.server?.strictPort ?? true
|
|
@@ -196,12 +196,13 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
198
|
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
199
|
+
const validEnvironmentNames = ["dev", "development", "local", "docker"];
|
|
199
200
|
if (command === "build" || env.LITESTAR_BYPASS_ENV_CHECK === "1") {
|
|
200
201
|
return;
|
|
201
202
|
}
|
|
202
|
-
if (typeof env.LITESTAR_MODE !== "undefined") {
|
|
203
|
+
if (typeof env.LITESTAR_MODE !== "undefined" && validEnvironmentNames.some((e) => e === env.LITESTAR_MODE)) {
|
|
203
204
|
throw Error(
|
|
204
|
-
"You should
|
|
205
|
+
"You should only run Vite dev server when Litestar is development mode. You should build your assets for production instead. To disable this ENV check you may set LITESTAR_BYPASS_ENV_CHECK=1"
|
|
205
206
|
);
|
|
206
207
|
}
|
|
207
208
|
if (typeof env.CI !== "undefined") {
|
|
@@ -211,7 +212,7 @@ function ensureCommandShouldRunInEnvironment(command, env) {
|
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
function litestarVersion() {
|
|
214
|
-
return "";
|
|
215
|
+
return "X.Y.Z";
|
|
215
216
|
}
|
|
216
217
|
function pluginVersion() {
|
|
217
218
|
try {
|
|
@@ -242,14 +243,6 @@ function resolvePluginConfig(config) {
|
|
|
242
243
|
);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
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
246
|
if (typeof config.bundleDirectory === "string") {
|
|
254
247
|
config.bundleDirectory = config.bundleDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
255
248
|
if (config.bundleDirectory === "") {
|
|
@@ -266,9 +259,8 @@ function resolvePluginConfig(config) {
|
|
|
266
259
|
}
|
|
267
260
|
return {
|
|
268
261
|
input: config.input,
|
|
269
|
-
assetUrl: config.assetUrl
|
|
262
|
+
assetUrl: config.assetUrl ?? "static",
|
|
270
263
|
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
271
|
-
assetDirectory: config.assetDirectory ?? import_path.default.join(config.resourceDirectory ?? "/resources/", "assets"),
|
|
272
264
|
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
273
265
|
ssr: config.ssr ?? config.input,
|
|
274
266
|
ssrOutputDirectory: config.ssrOutputDirectory ?? import_path.default.join(config.resourceDirectory ?? "resources", "bootstrap/ssr"),
|
|
@@ -321,7 +313,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
321
313
|
const protocol = clientProtocol ?? serverProtocol;
|
|
322
314
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
323
315
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
324
|
-
const remoteHost = process.env.
|
|
316
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
325
317
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
326
318
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
327
319
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
@@ -346,12 +338,12 @@ function noExternalInertiaHelpers(config) {
|
|
|
346
338
|
];
|
|
347
339
|
}
|
|
348
340
|
function resolveEnvironmentServerConfig(env) {
|
|
349
|
-
if (!env.
|
|
341
|
+
if (!env.VITE_SERVER_KEY && !env.VITE_SERVER_CERT) {
|
|
350
342
|
return;
|
|
351
343
|
}
|
|
352
|
-
if (!import_fs.default.existsSync(env.
|
|
344
|
+
if (!import_fs.default.existsSync(env.VITE_SERVER_KEY) || !import_fs.default.existsSync(env.VITE_SERVER_CERT)) {
|
|
353
345
|
throw Error(
|
|
354
|
-
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured
|
|
346
|
+
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured VITE_SERVER_KEY: [${env.VITE_SERVER_KEY}] and VITE_SERVER_CERT: [${env.VITE_SERVER_CERT}].`
|
|
355
347
|
);
|
|
356
348
|
}
|
|
357
349
|
const host = resolveHostFromEnv(env);
|
|
@@ -364,8 +356,8 @@ function resolveEnvironmentServerConfig(env) {
|
|
|
364
356
|
hmr: { host },
|
|
365
357
|
host,
|
|
366
358
|
https: {
|
|
367
|
-
key: import_fs.default.readFileSync(env.
|
|
368
|
-
cert: import_fs.default.readFileSync(env.
|
|
359
|
+
key: import_fs.default.readFileSync(env.VITE_SERVER_KEY),
|
|
360
|
+
cert: import_fs.default.readFileSync(env.VITE_SERVER_CERT)
|
|
369
361
|
}
|
|
370
362
|
};
|
|
371
363
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -23,12 +23,6 @@ interface PluginConfig {
|
|
|
23
23
|
* @default 'resources'
|
|
24
24
|
*/
|
|
25
25
|
resourceDirectory?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Litestar's public assets directory. These are the assets that Vite will serve when developing.
|
|
28
|
-
*
|
|
29
|
-
* @default '${resourceDirectory}/assets'
|
|
30
|
-
*/
|
|
31
|
-
assetDirectory?: string;
|
|
32
26
|
/**
|
|
33
27
|
* The path to the "hot" file.
|
|
34
28
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -35,7 +35,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
35
35
|
userConfig = config;
|
|
36
36
|
const ssr = !!userConfig.build?.ssr;
|
|
37
37
|
const env = loadEnv(mode, userConfig.envDir || process.cwd(), "");
|
|
38
|
-
const assetUrl = env.
|
|
38
|
+
const assetUrl = env.ASSET_URL || pluginConfig.assetUrl;
|
|
39
39
|
const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
|
|
40
40
|
pluginConfig.detectTls
|
|
41
41
|
) ?? resolveEnvironmentServerConfig(env) : void 0;
|
|
@@ -53,7 +53,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
53
53
|
},
|
|
54
54
|
server: {
|
|
55
55
|
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
56
|
-
...process.env.
|
|
56
|
+
...process.env.VITE_ALLOW_REMOTE ? {
|
|
57
57
|
host: userConfig.server?.host ?? "0.0.0.0",
|
|
58
58
|
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
59
59
|
strictPort: userConfig.server?.strictPort ?? true
|
|
@@ -167,12 +167,13 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
170
|
+
const validEnvironmentNames = ["dev", "development", "local", "docker"];
|
|
170
171
|
if (command === "build" || env.LITESTAR_BYPASS_ENV_CHECK === "1") {
|
|
171
172
|
return;
|
|
172
173
|
}
|
|
173
|
-
if (typeof env.LITESTAR_MODE !== "undefined") {
|
|
174
|
+
if (typeof env.LITESTAR_MODE !== "undefined" && validEnvironmentNames.some((e) => e === env.LITESTAR_MODE)) {
|
|
174
175
|
throw Error(
|
|
175
|
-
"You should
|
|
176
|
+
"You should only run Vite dev server when Litestar is development mode. You should build your assets for production instead. To disable this ENV check you may set LITESTAR_BYPASS_ENV_CHECK=1"
|
|
176
177
|
);
|
|
177
178
|
}
|
|
178
179
|
if (typeof env.CI !== "undefined") {
|
|
@@ -182,7 +183,7 @@ function ensureCommandShouldRunInEnvironment(command, env) {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
function litestarVersion() {
|
|
185
|
-
return "";
|
|
186
|
+
return "X.Y.Z";
|
|
186
187
|
}
|
|
187
188
|
function pluginVersion() {
|
|
188
189
|
try {
|
|
@@ -213,14 +214,6 @@ function resolvePluginConfig(config) {
|
|
|
213
214
|
);
|
|
214
215
|
}
|
|
215
216
|
}
|
|
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
217
|
if (typeof config.bundleDirectory === "string") {
|
|
225
218
|
config.bundleDirectory = config.bundleDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
226
219
|
if (config.bundleDirectory === "") {
|
|
@@ -237,9 +230,8 @@ function resolvePluginConfig(config) {
|
|
|
237
230
|
}
|
|
238
231
|
return {
|
|
239
232
|
input: config.input,
|
|
240
|
-
assetUrl: config.assetUrl
|
|
233
|
+
assetUrl: config.assetUrl ?? "static",
|
|
241
234
|
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
242
|
-
assetDirectory: config.assetDirectory ?? path.join(config.resourceDirectory ?? "/resources/", "assets"),
|
|
243
235
|
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
244
236
|
ssr: config.ssr ?? config.input,
|
|
245
237
|
ssrOutputDirectory: config.ssrOutputDirectory ?? path.join(config.resourceDirectory ?? "resources", "bootstrap/ssr"),
|
|
@@ -292,7 +284,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
292
284
|
const protocol = clientProtocol ?? serverProtocol;
|
|
293
285
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
294
286
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
295
|
-
const remoteHost = process.env.
|
|
287
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
296
288
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
297
289
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
298
290
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
@@ -317,12 +309,12 @@ function noExternalInertiaHelpers(config) {
|
|
|
317
309
|
];
|
|
318
310
|
}
|
|
319
311
|
function resolveEnvironmentServerConfig(env) {
|
|
320
|
-
if (!env.
|
|
312
|
+
if (!env.VITE_SERVER_KEY && !env.VITE_SERVER_CERT) {
|
|
321
313
|
return;
|
|
322
314
|
}
|
|
323
|
-
if (!fs.existsSync(env.
|
|
315
|
+
if (!fs.existsSync(env.VITE_SERVER_KEY) || !fs.existsSync(env.VITE_SERVER_CERT)) {
|
|
324
316
|
throw Error(
|
|
325
|
-
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured
|
|
317
|
+
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured VITE_SERVER_KEY: [${env.VITE_SERVER_KEY}] and VITE_SERVER_CERT: [${env.VITE_SERVER_CERT}].`
|
|
326
318
|
);
|
|
327
319
|
}
|
|
328
320
|
const host = resolveHostFromEnv(env);
|
|
@@ -335,8 +327,8 @@ function resolveEnvironmentServerConfig(env) {
|
|
|
335
327
|
hmr: { host },
|
|
336
328
|
host,
|
|
337
329
|
https: {
|
|
338
|
-
key: fs.readFileSync(env.
|
|
339
|
-
cert: fs.readFileSync(env.
|
|
330
|
+
key: fs.readFileSync(env.VITE_SERVER_KEY),
|
|
331
|
+
cert: fs.readFileSync(env.VITE_SERVER_CERT)
|
|
340
332
|
}
|
|
341
333
|
};
|
|
342
334
|
}
|