litestar-vite-plugin 0.1.4 → 0.1.7
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/README.md +13 -1
- package/dist/index.cjs +12 -18
- package/dist/index.d.ts +4 -10
- package/dist/index.mjs +12 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
# Litestar Vite Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Notice** This is experimental software
|
|
4
|
+
|
|
5
|
+
## What is this?
|
|
6
|
+
|
|
7
|
+
This is a library for Litestar and Vite that makes integration between the the two easier.
|
|
8
|
+
|
|
9
|
+
For details on usage, use the `litestar-vite` [plugin](https://github.com/cofin/litestar-vite)
|
|
10
|
+
|
|
11
|
+
## Credit
|
|
12
|
+
|
|
13
|
+
The team at Laravel have done an incredible job at making it easier to use common JS/TS frameworks with the framework.
|
|
14
|
+
|
|
15
|
+
This plugin is more than a little inspired by the worker here [Laravel's Vite Integration](https://github.com/laravel/vite-plugin)
|
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ const refreshPaths = [
|
|
|
40
40
|
"**/*.py",
|
|
41
41
|
"**/*.j2",
|
|
42
42
|
"**/*.html.j2",
|
|
43
|
+
"**/*.html",
|
|
43
44
|
"**/assets/**/*"
|
|
44
45
|
];
|
|
45
46
|
function litestar(config) {
|
|
@@ -63,7 +64,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
63
64
|
userConfig = config;
|
|
64
65
|
const ssr = !!userConfig.build?.ssr;
|
|
65
66
|
const env = (0, import_vite.loadEnv)(mode, userConfig.envDir || process.cwd(), "");
|
|
66
|
-
const assetUrl = env.
|
|
67
|
+
const assetUrl = env.LITESTAR_ASSET_URL || pluginConfig.assetUrl;
|
|
67
68
|
const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
|
|
68
69
|
pluginConfig.detectTls
|
|
69
70
|
) ?? resolveEnvironmentServerConfig(env) : void 0;
|
|
@@ -81,7 +82,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
81
82
|
},
|
|
82
83
|
server: {
|
|
83
84
|
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
84
|
-
...process.env.
|
|
85
|
+
...process.env.LITESTAR_VITE_ALLOW_REMOTE ? {
|
|
85
86
|
host: userConfig.server?.host ?? "0.0.0.0",
|
|
86
87
|
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
87
88
|
strictPort: userConfig.server?.strictPort ?? true
|
|
@@ -233,12 +234,6 @@ function resolvePluginConfig(config) {
|
|
|
233
234
|
'litestar-vite-plugin: missing configuration for "input".'
|
|
234
235
|
);
|
|
235
236
|
}
|
|
236
|
-
if (typeof config.rootDirectory === "undefined") {
|
|
237
|
-
config.rootDirectory = "";
|
|
238
|
-
}
|
|
239
|
-
if (typeof config.rootDirectory === "string") {
|
|
240
|
-
config.rootDirectory = config.rootDirectory.trim().replace(/^\/+/, "");
|
|
241
|
-
}
|
|
242
237
|
if (typeof config.resourceDirectory === "string") {
|
|
243
238
|
config.resourceDirectory = config.resourceDirectory.trim().replace(/^\/+/, "");
|
|
244
239
|
if (config.resourceDirectory === "") {
|
|
@@ -255,11 +250,11 @@ function resolvePluginConfig(config) {
|
|
|
255
250
|
);
|
|
256
251
|
}
|
|
257
252
|
}
|
|
258
|
-
if (typeof config.
|
|
259
|
-
config.
|
|
260
|
-
if (config.
|
|
253
|
+
if (typeof config.bundleDirectory === "string") {
|
|
254
|
+
config.bundleDirectory = config.bundleDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
255
|
+
if (config.bundleDirectory === "") {
|
|
261
256
|
throw new Error(
|
|
262
|
-
"litestar-vite-plugin:
|
|
257
|
+
"litestar-vite-plugin: bundleDirectory must be a subdirectory. E.g. 'public'."
|
|
263
258
|
);
|
|
264
259
|
}
|
|
265
260
|
}
|
|
@@ -272,10 +267,9 @@ function resolvePluginConfig(config) {
|
|
|
272
267
|
return {
|
|
273
268
|
input: config.input,
|
|
274
269
|
assetUrl: config.assetUrl || (config.assetUrl ?? "static"),
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
buildDirectory: config.buildDirectory || (config.buildDirectory ?? "public"),
|
|
270
|
+
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
271
|
+
assetDirectory: config.assetDirectory ?? "assets",
|
|
272
|
+
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
279
273
|
ssr: config.ssr ?? config.input,
|
|
280
274
|
ssrOutputDirectory: config.ssrOutputDirectory ?? "bootstrap/ssr",
|
|
281
275
|
refresh: config.refresh ?? false,
|
|
@@ -297,7 +291,7 @@ function resolveOutDir(config, ssr) {
|
|
|
297
291
|
if (ssr) {
|
|
298
292
|
return config.ssrOutputDirectory;
|
|
299
293
|
}
|
|
300
|
-
return import_path.default.join(config.
|
|
294
|
+
return import_path.default.join(config.bundleDirectory);
|
|
301
295
|
}
|
|
302
296
|
function resolveFullReloadConfig({
|
|
303
297
|
refresh: config
|
|
@@ -327,7 +321,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
327
321
|
const protocol = clientProtocol ?? serverProtocol;
|
|
328
322
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
329
323
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
330
|
-
const remoteHost = process.env.
|
|
324
|
+
const remoteHost = process.env.LITESTAR_VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
331
325
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
332
326
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
333
327
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,17 +12,11 @@ interface PluginConfig {
|
|
|
12
12
|
*/
|
|
13
13
|
assetUrl?: string;
|
|
14
14
|
/**
|
|
15
|
-
* The
|
|
16
|
-
*
|
|
17
|
-
* @default undefined
|
|
18
|
-
*/
|
|
19
|
-
rootDirectory?: string | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* The public directory where all compiled assets should be written.
|
|
15
|
+
* The public directory where all compiled/bundled assets should be written.
|
|
22
16
|
*
|
|
23
17
|
* @default 'public'
|
|
24
18
|
*/
|
|
25
|
-
|
|
19
|
+
bundleDirectory?: string;
|
|
26
20
|
/**
|
|
27
21
|
* The directory where all typescript/javascript source are written. This is used as the default "@" alias is pointed.
|
|
28
22
|
*
|
|
@@ -38,7 +32,7 @@ interface PluginConfig {
|
|
|
38
32
|
/**
|
|
39
33
|
* The path to the "hot" file.
|
|
40
34
|
*
|
|
41
|
-
* @default `${
|
|
35
|
+
* @default `${bundleDirectory}/hot`
|
|
42
36
|
*/
|
|
43
37
|
hotFile?: string;
|
|
44
38
|
/**
|
|
@@ -48,7 +42,7 @@ interface PluginConfig {
|
|
|
48
42
|
/**
|
|
49
43
|
* The directory where the SSR bundle should be written.
|
|
50
44
|
*
|
|
51
|
-
* @default '${
|
|
45
|
+
* @default '${bundleDirectory}/bootstrap/ssr'
|
|
52
46
|
*/
|
|
53
47
|
ssrOutputDirectory?: string;
|
|
54
48
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ const refreshPaths = [
|
|
|
11
11
|
"**/*.py",
|
|
12
12
|
"**/*.j2",
|
|
13
13
|
"**/*.html.j2",
|
|
14
|
+
"**/*.html",
|
|
14
15
|
"**/assets/**/*"
|
|
15
16
|
];
|
|
16
17
|
function litestar(config) {
|
|
@@ -34,7 +35,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
34
35
|
userConfig = config;
|
|
35
36
|
const ssr = !!userConfig.build?.ssr;
|
|
36
37
|
const env = loadEnv(mode, userConfig.envDir || process.cwd(), "");
|
|
37
|
-
const assetUrl = env.
|
|
38
|
+
const assetUrl = env.LITESTAR_ASSET_URL || pluginConfig.assetUrl;
|
|
38
39
|
const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
|
|
39
40
|
pluginConfig.detectTls
|
|
40
41
|
) ?? resolveEnvironmentServerConfig(env) : void 0;
|
|
@@ -52,7 +53,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
52
53
|
},
|
|
53
54
|
server: {
|
|
54
55
|
origin: userConfig.server?.origin ?? "__litestar_vite_placeholder__",
|
|
55
|
-
...process.env.
|
|
56
|
+
...process.env.LITESTAR_VITE_ALLOW_REMOTE ? {
|
|
56
57
|
host: userConfig.server?.host ?? "0.0.0.0",
|
|
57
58
|
port: userConfig.server?.port ?? (env.VITE_PORT ? parseInt(env.VITE_PORT) : 5173),
|
|
58
59
|
strictPort: userConfig.server?.strictPort ?? true
|
|
@@ -204,12 +205,6 @@ function resolvePluginConfig(config) {
|
|
|
204
205
|
'litestar-vite-plugin: missing configuration for "input".'
|
|
205
206
|
);
|
|
206
207
|
}
|
|
207
|
-
if (typeof config.rootDirectory === "undefined") {
|
|
208
|
-
config.rootDirectory = "";
|
|
209
|
-
}
|
|
210
|
-
if (typeof config.rootDirectory === "string") {
|
|
211
|
-
config.rootDirectory = config.rootDirectory.trim().replace(/^\/+/, "");
|
|
212
|
-
}
|
|
213
208
|
if (typeof config.resourceDirectory === "string") {
|
|
214
209
|
config.resourceDirectory = config.resourceDirectory.trim().replace(/^\/+/, "");
|
|
215
210
|
if (config.resourceDirectory === "") {
|
|
@@ -226,11 +221,11 @@ function resolvePluginConfig(config) {
|
|
|
226
221
|
);
|
|
227
222
|
}
|
|
228
223
|
}
|
|
229
|
-
if (typeof config.
|
|
230
|
-
config.
|
|
231
|
-
if (config.
|
|
224
|
+
if (typeof config.bundleDirectory === "string") {
|
|
225
|
+
config.bundleDirectory = config.bundleDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
|
|
226
|
+
if (config.bundleDirectory === "") {
|
|
232
227
|
throw new Error(
|
|
233
|
-
"litestar-vite-plugin:
|
|
228
|
+
"litestar-vite-plugin: bundleDirectory must be a subdirectory. E.g. 'public'."
|
|
234
229
|
);
|
|
235
230
|
}
|
|
236
231
|
}
|
|
@@ -243,10 +238,9 @@ function resolvePluginConfig(config) {
|
|
|
243
238
|
return {
|
|
244
239
|
input: config.input,
|
|
245
240
|
assetUrl: config.assetUrl || (config.assetUrl ?? "static"),
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
buildDirectory: config.buildDirectory || (config.buildDirectory ?? "public"),
|
|
241
|
+
resourceDirectory: config.resourceDirectory ?? "/resources/",
|
|
242
|
+
assetDirectory: config.assetDirectory ?? "assets",
|
|
243
|
+
bundleDirectory: config.bundleDirectory || (config.bundleDirectory ?? "public"),
|
|
250
244
|
ssr: config.ssr ?? config.input,
|
|
251
245
|
ssrOutputDirectory: config.ssrOutputDirectory ?? "bootstrap/ssr",
|
|
252
246
|
refresh: config.refresh ?? false,
|
|
@@ -268,7 +262,7 @@ function resolveOutDir(config, ssr) {
|
|
|
268
262
|
if (ssr) {
|
|
269
263
|
return config.ssrOutputDirectory;
|
|
270
264
|
}
|
|
271
|
-
return path.join(config.
|
|
265
|
+
return path.join(config.bundleDirectory);
|
|
272
266
|
}
|
|
273
267
|
function resolveFullReloadConfig({
|
|
274
268
|
refresh: config
|
|
@@ -298,7 +292,7 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
298
292
|
const protocol = clientProtocol ?? serverProtocol;
|
|
299
293
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
300
294
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
301
|
-
const remoteHost = process.env.
|
|
295
|
+
const remoteHost = process.env.LITESTAR_VITE_ALLOW_REMOTE && !userConfig.server?.host ? "localhost" : null;
|
|
302
296
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
303
297
|
const host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
304
298
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|