litestar-vite-plugin 0.4.0 → 0.4.2
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 +16 -14
- package/dist/index.mjs +16 -14
- 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;
|
|
@@ -72,6 +72,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
72
72
|
return {
|
|
73
73
|
base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : pluginConfig.assetUrl),
|
|
74
74
|
publicDir: userConfig.publicDir ?? false,
|
|
75
|
+
clearScreen: false,
|
|
75
76
|
build: {
|
|
76
77
|
manifest: userConfig.build?.manifest ?? !ssr,
|
|
77
78
|
outDir: userConfig.build?.outDir ?? resolveOutDir(pluginConfig, ssr),
|
|
@@ -82,7 +83,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
82
83
|
},
|
|
83
84
|
server: {
|
|
84
85
|
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
85
|
-
...process.env.
|
|
86
|
+
...process.env.VITE_ALLOW_REMOTE ? {
|
|
86
87
|
host: userConfig.server?.host ?? "0.0.0.0",
|
|
87
88
|
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
88
89
|
strictPort: userConfig.server?.strictPort ?? true
|
|
@@ -173,9 +174,9 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
173
174
|
}
|
|
174
175
|
};
|
|
175
176
|
process.on("exit", clean);
|
|
176
|
-
process.on("SIGINT", process.exit);
|
|
177
|
-
process.on("SIGTERM", process.exit);
|
|
178
|
-
process.on("SIGHUP", process.exit);
|
|
177
|
+
process.on("SIGINT", process.exit(0));
|
|
178
|
+
process.on("SIGTERM", process.exit(0));
|
|
179
|
+
process.on("SIGHUP", process.exit(0));
|
|
179
180
|
exitHandlersBound = true;
|
|
180
181
|
}
|
|
181
182
|
return () => server.middlewares.use((req, res, next) => {
|
|
@@ -196,12 +197,13 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
196
197
|
};
|
|
197
198
|
}
|
|
198
199
|
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
200
|
+
const validEnvironmentNames = ["dev", "development", "local", "docker"];
|
|
199
201
|
if (command === "build" || env.LITESTAR_BYPASS_ENV_CHECK === "1") {
|
|
200
202
|
return;
|
|
201
203
|
}
|
|
202
|
-
if (typeof env.LITESTAR_MODE !== "undefined") {
|
|
204
|
+
if (typeof env.LITESTAR_MODE !== "undefined" && validEnvironmentNames.some((e) => e === env.LITESTAR_MODE)) {
|
|
203
205
|
throw Error(
|
|
204
|
-
"You should
|
|
206
|
+
"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
207
|
);
|
|
206
208
|
}
|
|
207
209
|
if (typeof env.CI !== "undefined") {
|
|
@@ -258,7 +260,7 @@ function resolvePluginConfig(config) {
|
|
|
258
260
|
}
|
|
259
261
|
return {
|
|
260
262
|
input: config.input,
|
|
261
|
-
assetUrl: config.assetUrl
|
|
263
|
+
assetUrl: config.assetUrl ?? "static",
|
|
262
264
|
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
263
265
|
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
264
266
|
ssr: config.ssr ?? config.input,
|
|
@@ -312,7 +314,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
312
314
|
const protocol = clientProtocol ?? serverProtocol;
|
|
313
315
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
314
316
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
315
|
-
const remoteHost = process.env.
|
|
317
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
316
318
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
317
319
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
318
320
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
@@ -337,12 +339,12 @@ function noExternalInertiaHelpers(config) {
|
|
|
337
339
|
];
|
|
338
340
|
}
|
|
339
341
|
function resolveEnvironmentServerConfig(env) {
|
|
340
|
-
if (!env.
|
|
342
|
+
if (!env.VITE_SERVER_KEY && !env.VITE_SERVER_CERT) {
|
|
341
343
|
return;
|
|
342
344
|
}
|
|
343
|
-
if (!import_fs.default.existsSync(env.
|
|
345
|
+
if (!import_fs.default.existsSync(env.VITE_SERVER_KEY) || !import_fs.default.existsSync(env.VITE_SERVER_CERT)) {
|
|
344
346
|
throw Error(
|
|
345
|
-
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured
|
|
347
|
+
`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
348
|
);
|
|
347
349
|
}
|
|
348
350
|
const host = resolveHostFromEnv(env);
|
|
@@ -355,8 +357,8 @@ function resolveEnvironmentServerConfig(env) {
|
|
|
355
357
|
hmr: { host },
|
|
356
358
|
host,
|
|
357
359
|
https: {
|
|
358
|
-
key: import_fs.default.readFileSync(env.
|
|
359
|
-
cert: import_fs.default.readFileSync(env.
|
|
360
|
+
key: import_fs.default.readFileSync(env.VITE_SERVER_KEY),
|
|
361
|
+
cert: import_fs.default.readFileSync(env.VITE_SERVER_CERT)
|
|
360
362
|
}
|
|
361
363
|
};
|
|
362
364
|
}
|
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;
|
|
@@ -43,6 +43,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
43
43
|
return {
|
|
44
44
|
base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : pluginConfig.assetUrl),
|
|
45
45
|
publicDir: userConfig.publicDir ?? false,
|
|
46
|
+
clearScreen: false,
|
|
46
47
|
build: {
|
|
47
48
|
manifest: userConfig.build?.manifest ?? !ssr,
|
|
48
49
|
outDir: userConfig.build?.outDir ?? resolveOutDir(pluginConfig, ssr),
|
|
@@ -53,7 +54,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
53
54
|
},
|
|
54
55
|
server: {
|
|
55
56
|
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
56
|
-
...process.env.
|
|
57
|
+
...process.env.VITE_ALLOW_REMOTE ? {
|
|
57
58
|
host: userConfig.server?.host ?? "0.0.0.0",
|
|
58
59
|
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
59
60
|
strictPort: userConfig.server?.strictPort ?? true
|
|
@@ -144,9 +145,9 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
144
145
|
}
|
|
145
146
|
};
|
|
146
147
|
process.on("exit", clean);
|
|
147
|
-
process.on("SIGINT", process.exit);
|
|
148
|
-
process.on("SIGTERM", process.exit);
|
|
149
|
-
process.on("SIGHUP", process.exit);
|
|
148
|
+
process.on("SIGINT", process.exit(0));
|
|
149
|
+
process.on("SIGTERM", process.exit(0));
|
|
150
|
+
process.on("SIGHUP", process.exit(0));
|
|
150
151
|
exitHandlersBound = true;
|
|
151
152
|
}
|
|
152
153
|
return () => server.middlewares.use((req, res, next) => {
|
|
@@ -167,12 +168,13 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
167
168
|
};
|
|
168
169
|
}
|
|
169
170
|
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
171
|
+
const validEnvironmentNames = ["dev", "development", "local", "docker"];
|
|
170
172
|
if (command === "build" || env.LITESTAR_BYPASS_ENV_CHECK === "1") {
|
|
171
173
|
return;
|
|
172
174
|
}
|
|
173
|
-
if (typeof env.LITESTAR_MODE !== "undefined") {
|
|
175
|
+
if (typeof env.LITESTAR_MODE !== "undefined" && validEnvironmentNames.some((e) => e === env.LITESTAR_MODE)) {
|
|
174
176
|
throw Error(
|
|
175
|
-
"You should
|
|
177
|
+
"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
178
|
);
|
|
177
179
|
}
|
|
178
180
|
if (typeof env.CI !== "undefined") {
|
|
@@ -229,7 +231,7 @@ function resolvePluginConfig(config) {
|
|
|
229
231
|
}
|
|
230
232
|
return {
|
|
231
233
|
input: config.input,
|
|
232
|
-
assetUrl: config.assetUrl
|
|
234
|
+
assetUrl: config.assetUrl ?? "static",
|
|
233
235
|
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
234
236
|
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
235
237
|
ssr: config.ssr ?? config.input,
|
|
@@ -283,7 +285,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
283
285
|
const protocol = clientProtocol ?? serverProtocol;
|
|
284
286
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
285
287
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
286
|
-
const remoteHost = process.env.
|
|
288
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
287
289
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
288
290
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
289
291
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
@@ -308,12 +310,12 @@ function noExternalInertiaHelpers(config) {
|
|
|
308
310
|
];
|
|
309
311
|
}
|
|
310
312
|
function resolveEnvironmentServerConfig(env) {
|
|
311
|
-
if (!env.
|
|
313
|
+
if (!env.VITE_SERVER_KEY && !env.VITE_SERVER_CERT) {
|
|
312
314
|
return;
|
|
313
315
|
}
|
|
314
|
-
if (!fs.existsSync(env.
|
|
316
|
+
if (!fs.existsSync(env.VITE_SERVER_KEY) || !fs.existsSync(env.VITE_SERVER_CERT)) {
|
|
315
317
|
throw Error(
|
|
316
|
-
`Unable to find the certificate files specified in your environment. Ensure you have correctly configured
|
|
318
|
+
`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
319
|
);
|
|
318
320
|
}
|
|
319
321
|
const host = resolveHostFromEnv(env);
|
|
@@ -326,8 +328,8 @@ function resolveEnvironmentServerConfig(env) {
|
|
|
326
328
|
hmr: { host },
|
|
327
329
|
host,
|
|
328
330
|
https: {
|
|
329
|
-
key: fs.readFileSync(env.
|
|
330
|
-
cert: fs.readFileSync(env.
|
|
331
|
+
key: fs.readFileSync(env.VITE_SERVER_KEY),
|
|
332
|
+
cert: fs.readFileSync(env.VITE_SERVER_CERT)
|
|
331
333
|
}
|
|
332
334
|
};
|
|
333
335
|
}
|