litestar-vite-plugin 0.4.0 → 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 -12
- package/dist/index.mjs +13 -12
- 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 {
|
|
@@ -258,7 +259,7 @@ function resolvePluginConfig(config) {
|
|
|
258
259
|
}
|
|
259
260
|
return {
|
|
260
261
|
input: config.input,
|
|
261
|
-
assetUrl: config.assetUrl
|
|
262
|
+
assetUrl: config.assetUrl ?? "static",
|
|
262
263
|
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
263
264
|
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
264
265
|
ssr: config.ssr ?? config.input,
|
|
@@ -312,7 +313,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
312
313
|
const protocol = clientProtocol ?? serverProtocol;
|
|
313
314
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
314
315
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
315
|
-
const remoteHost = process.env.
|
|
316
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
316
317
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
317
318
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
318
319
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
@@ -337,12 +338,12 @@ function noExternalInertiaHelpers(config) {
|
|
|
337
338
|
];
|
|
338
339
|
}
|
|
339
340
|
function resolveEnvironmentServerConfig(env) {
|
|
340
|
-
if (!env.
|
|
341
|
+
if (!env.VITE_SERVER_KEY && !env.VITE_SERVER_CERT) {
|
|
341
342
|
return;
|
|
342
343
|
}
|
|
343
|
-
if (!import_fs.default.existsSync(env.
|
|
344
|
+
if (!import_fs.default.existsSync(env.VITE_SERVER_KEY) || !import_fs.default.existsSync(env.VITE_SERVER_CERT)) {
|
|
344
345
|
throw Error(
|
|
345
|
-
`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}].`
|
|
346
347
|
);
|
|
347
348
|
}
|
|
348
349
|
const host = resolveHostFromEnv(env);
|
|
@@ -355,8 +356,8 @@ function resolveEnvironmentServerConfig(env) {
|
|
|
355
356
|
hmr: { host },
|
|
356
357
|
host,
|
|
357
358
|
https: {
|
|
358
|
-
key: import_fs.default.readFileSync(env.
|
|
359
|
-
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)
|
|
360
361
|
}
|
|
361
362
|
};
|
|
362
363
|
}
|
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 {
|
|
@@ -229,7 +230,7 @@ function resolvePluginConfig(config) {
|
|
|
229
230
|
}
|
|
230
231
|
return {
|
|
231
232
|
input: config.input,
|
|
232
|
-
assetUrl: config.assetUrl
|
|
233
|
+
assetUrl: config.assetUrl ?? "static",
|
|
233
234
|
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
234
235
|
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
235
236
|
ssr: config.ssr ?? config.input,
|
|
@@ -283,7 +284,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
283
284
|
const protocol = clientProtocol ?? serverProtocol;
|
|
284
285
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
285
286
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
286
|
-
const remoteHost = process.env.
|
|
287
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
287
288
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
288
289
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
289
290
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
@@ -308,12 +309,12 @@ function noExternalInertiaHelpers(config) {
|
|
|
308
309
|
];
|
|
309
310
|
}
|
|
310
311
|
function resolveEnvironmentServerConfig(env) {
|
|
311
|
-
if (!env.
|
|
312
|
+
if (!env.VITE_SERVER_KEY && !env.VITE_SERVER_CERT) {
|
|
312
313
|
return;
|
|
313
314
|
}
|
|
314
|
-
if (!fs.existsSync(env.
|
|
315
|
+
if (!fs.existsSync(env.VITE_SERVER_KEY) || !fs.existsSync(env.VITE_SERVER_CERT)) {
|
|
315
316
|
throw Error(
|
|
316
|
-
`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}].`
|
|
317
318
|
);
|
|
318
319
|
}
|
|
319
320
|
const host = resolveHostFromEnv(env);
|
|
@@ -326,8 +327,8 @@ function resolveEnvironmentServerConfig(env) {
|
|
|
326
327
|
hmr: { host },
|
|
327
328
|
host,
|
|
328
329
|
https: {
|
|
329
|
-
key: fs.readFileSync(env.
|
|
330
|
-
cert: fs.readFileSync(env.
|
|
330
|
+
key: fs.readFileSync(env.VITE_SERVER_KEY),
|
|
331
|
+
cert: fs.readFileSync(env.VITE_SERVER_CERT)
|
|
331
332
|
}
|
|
332
333
|
};
|
|
333
334
|
}
|