litestar-vite-plugin 0.1.0 → 0.1.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 CHANGED
@@ -37,11 +37,10 @@ var import_vite = require("vite");
37
37
  var import_vite_plugin_full_reload = __toESM(require("vite-plugin-full-reload"));
38
38
  let exitHandlersBound = false;
39
39
  const refreshPaths = [
40
- "app/View/Components/**",
41
- "resources/views/**",
42
- "resources/lang/**",
43
- "lang/**",
44
- "routes/**"
40
+ "**/*.py",
41
+ "**/*.j2",
42
+ "**/*.html.j2",
43
+ "**/assets/**/*"
45
44
  ];
46
45
  function litestar(config) {
47
46
  const pluginConfig = resolvePluginConfig(config);
@@ -55,7 +54,7 @@ function resolveLitestarPlugin(pluginConfig) {
55
54
  let resolvedConfig;
56
55
  let userConfig;
57
56
  const defaultAliases = {
58
- "@": "/resources/js"
57
+ "@": pluginConfig.resourceDirectory || "/resources/"
59
58
  };
60
59
  return {
61
60
  name: "litestar",
@@ -64,11 +63,13 @@ function resolveLitestarPlugin(pluginConfig) {
64
63
  userConfig = config;
65
64
  const ssr = !!userConfig.build?.ssr;
66
65
  const env = (0, import_vite.loadEnv)(mode, userConfig.envDir || process.cwd(), "");
67
- const assetUrl = env.ASSET_URL ?? "";
68
- const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(pluginConfig.detectTls) ?? resolveEnvironmentServerConfig(env) : void 0;
66
+ const assetUrl = env.ASSET_URL || pluginConfig.assetUrl;
67
+ const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
68
+ pluginConfig.detectTls
69
+ ) ?? resolveEnvironmentServerConfig(env) : void 0;
69
70
  ensureCommandShouldRunInEnvironment(command, env);
70
71
  return {
71
- base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : ""),
72
+ base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : pluginConfig.assetUrl),
72
73
  publicDir: userConfig.publicDir ?? false,
73
74
  build: {
74
75
  manifest: userConfig.build?.manifest ?? !ssr,
@@ -119,7 +120,10 @@ function resolveLitestarPlugin(pluginConfig) {
119
120
  },
120
121
  transform(code) {
121
122
  if (resolvedConfig.command === "serve") {
122
- code = code.replace(/__litestar_vite_placeholder__/g, viteDevServerUrl);
123
+ code = code.replace(
124
+ /__litestar_vite_placeholder__/g,
125
+ viteDevServerUrl
126
+ );
123
127
  return pluginConfig.transformOnServe(code, viteDevServerUrl);
124
128
  }
125
129
  },
@@ -130,13 +134,34 @@ function resolveLitestarPlugin(pluginConfig) {
130
134
  const address = server.httpServer?.address();
131
135
  const isAddressInfo = (x) => typeof x === "object";
132
136
  if (isAddressInfo(address)) {
133
- viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
137
+ viteDevServerUrl = resolveDevServerUrl(
138
+ address,
139
+ server.config,
140
+ userConfig
141
+ );
134
142
  import_fs.default.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
135
143
  setTimeout(() => {
136
- server.config.logger.info(`
137
- ${import_picocolors.default.red(`${import_picocolors.default.bold("LITESTAR")} ${litestarVersion()}`)} ${import_picocolors.default.dim("plugin")} ${import_picocolors.default.bold(`v${pluginVersion()}`)}`);
144
+ server.config.logger.info(
145
+ `
146
+ ${import_picocolors.default.red(
147
+ `${import_picocolors.default.bold(
148
+ "LITESTAR"
149
+ )} ${litestarVersion()}`
150
+ )} ${import_picocolors.default.dim("plugin")} ${import_picocolors.default.bold(
151
+ `v${pluginVersion()}`
152
+ )}`
153
+ );
138
154
  server.config.logger.info("");
139
- server.config.logger.info(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("APP_URL")}: ${import_picocolors.default.cyan(appUrl.replace(/:(\d+)/, (_, port) => `:${import_picocolors.default.bold(port)}`))}`);
155
+ server.config.logger.info(
156
+ ` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
157
+ "APP_URL"
158
+ )}: ${import_picocolors.default.cyan(
159
+ appUrl.replace(
160
+ /:(\d+)/,
161
+ (_, port) => `:${import_picocolors.default.bold(port)}`
162
+ )
163
+ )}`
164
+ );
140
165
  }, 100);
141
166
  }
142
167
  });
@@ -156,7 +181,12 @@ function resolveLitestarPlugin(pluginConfig) {
156
181
  if (req.url === "/index.html") {
157
182
  res.statusCode = 404;
158
183
  res.end(
159
- import_fs.default.readFileSync(import_path.default.join(dirname(), "dev-server-index.html")).toString().replace(/{{ APP_URL }}/g, appUrl)
184
+ import_fs.default.readFileSync(
185
+ import_path.default.join(
186
+ dirname(),
187
+ "dev-server-index.html"
188
+ )
189
+ ).toString().replace(/{{ APP_URL }}/g, appUrl)
160
190
  );
161
191
  }
162
192
  next();
@@ -169,23 +199,24 @@ function ensureCommandShouldRunInEnvironment(command, env) {
169
199
  return;
170
200
  }
171
201
  if (typeof env.LITESTAR_MODE !== "undefined") {
172
- throw Error("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");
202
+ throw Error(
203
+ "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"
204
+ );
173
205
  }
174
206
  if (typeof env.CI !== "undefined") {
175
- throw Error("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");
207
+ throw Error(
208
+ "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"
209
+ );
176
210
  }
177
211
  }
178
212
  function litestarVersion() {
179
- try {
180
- const composer = JSON.parse(import_fs.default.readFileSync("composer.lock").toString());
181
- return composer.packages?.find((composerPackage) => composerPackage.name === "litestar/framework")?.version ?? "";
182
- } catch {
183
- return "";
184
- }
213
+ return "";
185
214
  }
186
215
  function pluginVersion() {
187
216
  try {
188
- return JSON.parse(import_fs.default.readFileSync(import_path.default.join(dirname(), "../package.json")).toString())?.version;
217
+ return JSON.parse(
218
+ import_fs.default.readFileSync(import_path.default.join(dirname(), "../package.json")).toString()
219
+ )?.version;
189
220
  } catch {
190
221
  return "";
191
222
  }
@@ -198,18 +229,38 @@ function resolvePluginConfig(config) {
198
229
  config = { input: config, ssr: config };
199
230
  }
200
231
  if (typeof config.input === "undefined") {
201
- throw new Error('litestar-vite-plugin: missing configuration for "input".');
232
+ throw new Error(
233
+ 'litestar-vite-plugin: missing configuration for "input".'
234
+ );
235
+ }
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
+ if (typeof config.resourceDirectory === "string") {
243
+ config.resourceDirectory = config.resourceDirectory.trim().replace(/^\/+/, "");
244
+ if (config.resourceDirectory === "") {
245
+ throw new Error(
246
+ "litestar-vite-plugin: resourceDirectory must be a subdirectory. E.g. 'resources'."
247
+ );
248
+ }
202
249
  }
203
- if (typeof config.publicDirectory === "string") {
204
- config.publicDirectory = config.publicDirectory.trim().replace(/^\/+/, "");
205
- if (config.publicDirectory === "") {
206
- throw new Error("litestar-vite-plugin: publicDirectory must be a subdirectory. E.g. 'public'.");
250
+ if (typeof config.assetDirectory === "string") {
251
+ config.assetDirectory = config.assetDirectory.trim().replace(/^\/+/, "");
252
+ if (config.assetDirectory === "") {
253
+ throw new Error(
254
+ "litestar-vite-plugin: assetDirectory must be a subdirectory. E.g. 'assets'."
255
+ );
207
256
  }
208
257
  }
209
258
  if (typeof config.buildDirectory === "string") {
210
259
  config.buildDirectory = config.buildDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
211
260
  if (config.buildDirectory === "") {
212
- throw new Error("litestar-vite-plugin: buildDirectory must be a subdirectory. E.g. 'build'.");
261
+ throw new Error(
262
+ "litestar-vite-plugin: buildDirectory must be a subdirectory. E.g. 'public'."
263
+ );
213
264
  }
214
265
  }
215
266
  if (typeof config.ssrOutputDirectory === "string") {
@@ -220,18 +271,21 @@ function resolvePluginConfig(config) {
220
271
  }
221
272
  return {
222
273
  input: config.input,
223
- publicDirectory: config.publicDirectory ?? "public",
224
- buildDirectory: config.buildDirectory ?? "build",
274
+ assetUrl: config.assetUrl || (config.assetUrl ?? "static"),
275
+ rootDirectory: config.rootDirectory ?? void 0,
276
+ resourceDirectory: config.resourceDirectory ?? "",
277
+ assetDirectory: config.assetDirectory ?? "",
278
+ buildDirectory: config.buildDirectory || (config.buildDirectory ?? "public"),
225
279
  ssr: config.ssr ?? config.input,
226
280
  ssrOutputDirectory: config.ssrOutputDirectory ?? "bootstrap/ssr",
227
281
  refresh: config.refresh ?? false,
228
- hotFile: config.hotFile ?? import_path.default.join(config.publicDirectory ?? "public", "hot"),
282
+ hotFile: config.hotFile ?? import_path.default.join(config.assetDirectory ?? "hot"),
229
283
  detectTls: config.detectTls ?? false,
230
284
  transformOnServe: config.transformOnServe ?? ((code) => code)
231
285
  };
232
286
  }
233
287
  function resolveBase(config, assetUrl) {
234
- return assetUrl + (assetUrl.endsWith("/") ? "" : "/") + config.buildDirectory + "/";
288
+ return assetUrl + (config.assetUrl.endsWith("/") ? "" : "/");
235
289
  }
236
290
  function resolveInput(config, ssr) {
237
291
  if (ssr) {
@@ -243,9 +297,11 @@ function resolveOutDir(config, ssr) {
243
297
  if (ssr) {
244
298
  return config.ssrOutputDirectory;
245
299
  }
246
- return import_path.default.join(config.publicDirectory, config.buildDirectory);
300
+ return import_path.default.join(config.buildDirectory);
247
301
  }
248
- function resolveFullReloadConfig({ refresh: config }) {
302
+ function resolveFullReloadConfig({
303
+ refresh: config
304
+ }) {
249
305
  if (typeof config === "boolean") {
250
306
  return [];
251
307
  }
@@ -300,11 +356,15 @@ function resolveEnvironmentServerConfig(env) {
300
356
  return;
301
357
  }
302
358
  if (!import_fs.default.existsSync(env.VITE_DEV_SERVER_KEY) || !import_fs.default.existsSync(env.VITE_DEV_SERVER_CERT)) {
303
- throw Error(`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}].`);
359
+ throw Error(
360
+ `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}].`
361
+ );
304
362
  }
305
363
  const host = resolveHostFromEnv(env);
306
364
  if (!host) {
307
- throw Error(`Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`);
365
+ throw Error(
366
+ `Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`
367
+ );
308
368
  }
309
369
  return {
310
370
  hmr: { host },
@@ -331,7 +391,9 @@ function resolveDevelopmentEnvironmentServerConfig(host) {
331
391
  const keyPath = import_path.default.resolve(configPath, "certs", `${host}.key`);
332
392
  const certPath = import_path.default.resolve(configPath, "certs", `${host}.crt`);
333
393
  if (!import_fs.default.existsSync(keyPath) || !import_fs.default.existsSync(certPath)) {
334
- throw Error(`Unable to find certificate files for your host [${host}] in the [${configPath}/certs] directory.`);
394
+ throw Error(
395
+ `Unable to find certificate files for your host [${host}] in the [${configPath}/certs] directory.`
396
+ );
335
397
  }
336
398
  return {
337
399
  hmr: { host },
@@ -352,9 +414,13 @@ function determineDevelopmentEnvironmentConfigPath() {
352
414
  function resolveDevelopmentEnvironmentHost(configPath) {
353
415
  const configFile = import_path.default.resolve(configPath, "config.json");
354
416
  if (!import_fs.default.existsSync(configFile)) {
355
- throw Error(`Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`);
417
+ throw Error(
418
+ `Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`
419
+ );
356
420
  }
357
- const config = JSON.parse(import_fs.default.readFileSync(configFile, "utf-8"));
421
+ const config = JSON.parse(
422
+ import_fs.default.readFileSync(configFile, "utf-8")
423
+ );
358
424
  return import_path.default.basename(process.cwd()) + "." + config.tld;
359
425
  }
360
426
  function dirname() {
package/dist/index.d.ts CHANGED
@@ -1,26 +1,44 @@
1
- import { Plugin, UserConfig, ConfigEnv } from 'vite';
2
- import { Config as FullReloadConfig } from 'vite-plugin-full-reload';
1
+ import { Plugin, UserConfig, ConfigEnv } from "vite";
2
+ import { Config as FullReloadConfig } from "vite-plugin-full-reload";
3
3
  interface PluginConfig {
4
4
  /**
5
5
  * The path or paths of the entry points to compile.
6
6
  */
7
7
  input: string | string[];
8
8
  /**
9
- * Litestar's public directory.
9
+ * The base path to use for all asset URLs.
10
10
  *
11
- * @default 'public'
11
+ * @default '/static/'
12
+ */
13
+ assetUrl?: string;
14
+ /**
15
+ * The base directory for all Vite source
16
+ *
17
+ * @default undefined
12
18
  */
13
- publicDirectory?: string;
19
+ rootDirectory?: string | undefined;
14
20
  /**
15
- * The public subdirectory where compiled assets should be written.
21
+ * The public directory where all compiled assets should be written.
16
22
  *
17
- * @default 'build'
23
+ * @default 'public'
18
24
  */
19
25
  buildDirectory?: string;
26
+ /**
27
+ * The directory where all typescript/javascript source are written. This is used as the default "@" alias is pointed.
28
+ *
29
+ * @default 'resources'
30
+ */
31
+ resourceDirectory?: string;
32
+ /**
33
+ * Litestar's public assets directory. These are the assets that Vite will serve when developing.
34
+ *
35
+ * @default '${resourceDirectory}/assets'
36
+ */
37
+ assetDirectory?: string;
20
38
  /**
21
39
  * The path to the "hot" file.
22
40
  *
23
- * @default `${publicDirectory}/hot`
41
+ * @default `${assetDirectory}/hot`
24
42
  */
25
43
  hotFile?: string;
26
44
  /**
@@ -30,11 +48,11 @@ interface PluginConfig {
30
48
  /**
31
49
  * The directory where the SSR bundle should be written.
32
50
  *
33
- * @default 'bootstrap/ssr'
51
+ * @default '${assetDirectory}/bootstrap/ssr'
34
52
  */
35
53
  ssrOutputDirectory?: string;
36
54
  /**
37
- * Configuration for performing full page refresh on blade (or other) file changes.
55
+ * Configuration for performing full page refresh on python (or other) file changes.
38
56
  *
39
57
  * {@link https://github.com/ElMassimo/vite-plugin-full-reload}
40
58
  * @default false
@@ -58,7 +76,7 @@ interface RefreshConfig {
58
76
  interface LitestarPlugin extends Plugin {
59
77
  config: (config: UserConfig, env: ConfigEnv) => UserConfig;
60
78
  }
61
- type DevServerUrl = `${'http' | 'https'}://${string}:${number}`;
79
+ type DevServerUrl = `${"http" | "https"}://${string}:${number}`;
62
80
  export declare const refreshPaths: string[];
63
81
  /**
64
82
  * Litestar plugin for Vite.
package/dist/index.mjs CHANGED
@@ -2,15 +2,16 @@ import fs from "fs";
2
2
  import { fileURLToPath } from "url";
3
3
  import path from "path";
4
4
  import colors from "picocolors";
5
- import { loadEnv } from "vite";
5
+ import {
6
+ loadEnv
7
+ } from "vite";
6
8
  import fullReload from "vite-plugin-full-reload";
7
9
  let exitHandlersBound = false;
8
10
  const refreshPaths = [
9
- "app/View/Components/**",
10
- "resources/views/**",
11
- "resources/lang/**",
12
- "lang/**",
13
- "routes/**"
11
+ "**/*.py",
12
+ "**/*.j2",
13
+ "**/*.html.j2",
14
+ "**/assets/**/*"
14
15
  ];
15
16
  function litestar(config) {
16
17
  const pluginConfig = resolvePluginConfig(config);
@@ -24,7 +25,7 @@ function resolveLitestarPlugin(pluginConfig) {
24
25
  let resolvedConfig;
25
26
  let userConfig;
26
27
  const defaultAliases = {
27
- "@": "/resources/js"
28
+ "@": pluginConfig.resourceDirectory || "/resources/"
28
29
  };
29
30
  return {
30
31
  name: "litestar",
@@ -33,11 +34,13 @@ function resolveLitestarPlugin(pluginConfig) {
33
34
  userConfig = config;
34
35
  const ssr = !!userConfig.build?.ssr;
35
36
  const env = loadEnv(mode, userConfig.envDir || process.cwd(), "");
36
- const assetUrl = env.ASSET_URL ?? "";
37
- const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(pluginConfig.detectTls) ?? resolveEnvironmentServerConfig(env) : void 0;
37
+ const assetUrl = env.ASSET_URL || pluginConfig.assetUrl;
38
+ const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(
39
+ pluginConfig.detectTls
40
+ ) ?? resolveEnvironmentServerConfig(env) : void 0;
38
41
  ensureCommandShouldRunInEnvironment(command, env);
39
42
  return {
40
- base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : ""),
43
+ base: userConfig.base ?? (command === "build" ? resolveBase(pluginConfig, assetUrl) : pluginConfig.assetUrl),
41
44
  publicDir: userConfig.publicDir ?? false,
42
45
  build: {
43
46
  manifest: userConfig.build?.manifest ?? !ssr,
@@ -88,7 +91,10 @@ function resolveLitestarPlugin(pluginConfig) {
88
91
  },
89
92
  transform(code) {
90
93
  if (resolvedConfig.command === "serve") {
91
- code = code.replace(/__litestar_vite_placeholder__/g, viteDevServerUrl);
94
+ code = code.replace(
95
+ /__litestar_vite_placeholder__/g,
96
+ viteDevServerUrl
97
+ );
92
98
  return pluginConfig.transformOnServe(code, viteDevServerUrl);
93
99
  }
94
100
  },
@@ -99,13 +105,34 @@ function resolveLitestarPlugin(pluginConfig) {
99
105
  const address = server.httpServer?.address();
100
106
  const isAddressInfo = (x) => typeof x === "object";
101
107
  if (isAddressInfo(address)) {
102
- viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
108
+ viteDevServerUrl = resolveDevServerUrl(
109
+ address,
110
+ server.config,
111
+ userConfig
112
+ );
103
113
  fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
104
114
  setTimeout(() => {
105
- server.config.logger.info(`
106
- ${colors.red(`${colors.bold("LITESTAR")} ${litestarVersion()}`)} ${colors.dim("plugin")} ${colors.bold(`v${pluginVersion()}`)}`);
115
+ server.config.logger.info(
116
+ `
117
+ ${colors.red(
118
+ `${colors.bold(
119
+ "LITESTAR"
120
+ )} ${litestarVersion()}`
121
+ )} ${colors.dim("plugin")} ${colors.bold(
122
+ `v${pluginVersion()}`
123
+ )}`
124
+ );
107
125
  server.config.logger.info("");
108
- server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("APP_URL")}: ${colors.cyan(appUrl.replace(/:(\d+)/, (_, port) => `:${colors.bold(port)}`))}`);
126
+ server.config.logger.info(
127
+ ` ${colors.green("\u279C")} ${colors.bold(
128
+ "APP_URL"
129
+ )}: ${colors.cyan(
130
+ appUrl.replace(
131
+ /:(\d+)/,
132
+ (_, port) => `:${colors.bold(port)}`
133
+ )
134
+ )}`
135
+ );
109
136
  }, 100);
110
137
  }
111
138
  });
@@ -125,7 +152,12 @@ function resolveLitestarPlugin(pluginConfig) {
125
152
  if (req.url === "/index.html") {
126
153
  res.statusCode = 404;
127
154
  res.end(
128
- fs.readFileSync(path.join(dirname(), "dev-server-index.html")).toString().replace(/{{ APP_URL }}/g, appUrl)
155
+ fs.readFileSync(
156
+ path.join(
157
+ dirname(),
158
+ "dev-server-index.html"
159
+ )
160
+ ).toString().replace(/{{ APP_URL }}/g, appUrl)
129
161
  );
130
162
  }
131
163
  next();
@@ -138,23 +170,24 @@ function ensureCommandShouldRunInEnvironment(command, env) {
138
170
  return;
139
171
  }
140
172
  if (typeof env.LITESTAR_MODE !== "undefined") {
141
- throw Error("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");
173
+ throw Error(
174
+ "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"
175
+ );
142
176
  }
143
177
  if (typeof env.CI !== "undefined") {
144
- throw Error("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");
178
+ throw Error(
179
+ "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"
180
+ );
145
181
  }
146
182
  }
147
183
  function litestarVersion() {
148
- try {
149
- const composer = JSON.parse(fs.readFileSync("composer.lock").toString());
150
- return composer.packages?.find((composerPackage) => composerPackage.name === "litestar/framework")?.version ?? "";
151
- } catch {
152
- return "";
153
- }
184
+ return "";
154
185
  }
155
186
  function pluginVersion() {
156
187
  try {
157
- return JSON.parse(fs.readFileSync(path.join(dirname(), "../package.json")).toString())?.version;
188
+ return JSON.parse(
189
+ fs.readFileSync(path.join(dirname(), "../package.json")).toString()
190
+ )?.version;
158
191
  } catch {
159
192
  return "";
160
193
  }
@@ -167,18 +200,38 @@ function resolvePluginConfig(config) {
167
200
  config = { input: config, ssr: config };
168
201
  }
169
202
  if (typeof config.input === "undefined") {
170
- throw new Error('litestar-vite-plugin: missing configuration for "input".');
203
+ throw new Error(
204
+ 'litestar-vite-plugin: missing configuration for "input".'
205
+ );
206
+ }
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
+ if (typeof config.resourceDirectory === "string") {
214
+ config.resourceDirectory = config.resourceDirectory.trim().replace(/^\/+/, "");
215
+ if (config.resourceDirectory === "") {
216
+ throw new Error(
217
+ "litestar-vite-plugin: resourceDirectory must be a subdirectory. E.g. 'resources'."
218
+ );
219
+ }
171
220
  }
172
- if (typeof config.publicDirectory === "string") {
173
- config.publicDirectory = config.publicDirectory.trim().replace(/^\/+/, "");
174
- if (config.publicDirectory === "") {
175
- throw new Error("litestar-vite-plugin: publicDirectory must be a subdirectory. E.g. 'public'.");
221
+ if (typeof config.assetDirectory === "string") {
222
+ config.assetDirectory = config.assetDirectory.trim().replace(/^\/+/, "");
223
+ if (config.assetDirectory === "") {
224
+ throw new Error(
225
+ "litestar-vite-plugin: assetDirectory must be a subdirectory. E.g. 'assets'."
226
+ );
176
227
  }
177
228
  }
178
229
  if (typeof config.buildDirectory === "string") {
179
230
  config.buildDirectory = config.buildDirectory.trim().replace(/^\/+/, "").replace(/\/+$/, "");
180
231
  if (config.buildDirectory === "") {
181
- throw new Error("litestar-vite-plugin: buildDirectory must be a subdirectory. E.g. 'build'.");
232
+ throw new Error(
233
+ "litestar-vite-plugin: buildDirectory must be a subdirectory. E.g. 'public'."
234
+ );
182
235
  }
183
236
  }
184
237
  if (typeof config.ssrOutputDirectory === "string") {
@@ -189,18 +242,21 @@ function resolvePluginConfig(config) {
189
242
  }
190
243
  return {
191
244
  input: config.input,
192
- publicDirectory: config.publicDirectory ?? "public",
193
- buildDirectory: config.buildDirectory ?? "build",
245
+ assetUrl: config.assetUrl || (config.assetUrl ?? "static"),
246
+ rootDirectory: config.rootDirectory ?? void 0,
247
+ resourceDirectory: config.resourceDirectory ?? "",
248
+ assetDirectory: config.assetDirectory ?? "",
249
+ buildDirectory: config.buildDirectory || (config.buildDirectory ?? "public"),
194
250
  ssr: config.ssr ?? config.input,
195
251
  ssrOutputDirectory: config.ssrOutputDirectory ?? "bootstrap/ssr",
196
252
  refresh: config.refresh ?? false,
197
- hotFile: config.hotFile ?? path.join(config.publicDirectory ?? "public", "hot"),
253
+ hotFile: config.hotFile ?? path.join(config.assetDirectory ?? "hot"),
198
254
  detectTls: config.detectTls ?? false,
199
255
  transformOnServe: config.transformOnServe ?? ((code) => code)
200
256
  };
201
257
  }
202
258
  function resolveBase(config, assetUrl) {
203
- return assetUrl + (assetUrl.endsWith("/") ? "" : "/") + config.buildDirectory + "/";
259
+ return assetUrl + (config.assetUrl.endsWith("/") ? "" : "/");
204
260
  }
205
261
  function resolveInput(config, ssr) {
206
262
  if (ssr) {
@@ -212,9 +268,11 @@ function resolveOutDir(config, ssr) {
212
268
  if (ssr) {
213
269
  return config.ssrOutputDirectory;
214
270
  }
215
- return path.join(config.publicDirectory, config.buildDirectory);
271
+ return path.join(config.buildDirectory);
216
272
  }
217
- function resolveFullReloadConfig({ refresh: config }) {
273
+ function resolveFullReloadConfig({
274
+ refresh: config
275
+ }) {
218
276
  if (typeof config === "boolean") {
219
277
  return [];
220
278
  }
@@ -269,11 +327,15 @@ function resolveEnvironmentServerConfig(env) {
269
327
  return;
270
328
  }
271
329
  if (!fs.existsSync(env.VITE_DEV_SERVER_KEY) || !fs.existsSync(env.VITE_DEV_SERVER_CERT)) {
272
- throw Error(`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}].`);
330
+ throw Error(
331
+ `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}].`
332
+ );
273
333
  }
274
334
  const host = resolveHostFromEnv(env);
275
335
  if (!host) {
276
- throw Error(`Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`);
336
+ throw Error(
337
+ `Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`
338
+ );
277
339
  }
278
340
  return {
279
341
  hmr: { host },
@@ -300,7 +362,9 @@ function resolveDevelopmentEnvironmentServerConfig(host) {
300
362
  const keyPath = path.resolve(configPath, "certs", `${host}.key`);
301
363
  const certPath = path.resolve(configPath, "certs", `${host}.crt`);
302
364
  if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) {
303
- throw Error(`Unable to find certificate files for your host [${host}] in the [${configPath}/certs] directory.`);
365
+ throw Error(
366
+ `Unable to find certificate files for your host [${host}] in the [${configPath}/certs] directory.`
367
+ );
304
368
  }
305
369
  return {
306
370
  hmr: { host },
@@ -321,9 +385,13 @@ function determineDevelopmentEnvironmentConfigPath() {
321
385
  function resolveDevelopmentEnvironmentHost(configPath) {
322
386
  const configFile = path.resolve(configPath, "config.json");
323
387
  if (!fs.existsSync(configFile)) {
324
- throw Error(`Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`);
388
+ throw Error(
389
+ `Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`
390
+ );
325
391
  }
326
- const config = JSON.parse(fs.readFileSync(configFile, "utf-8"));
392
+ const config = JSON.parse(
393
+ fs.readFileSync(configFile, "utf-8")
394
+ );
327
395
  return path.basename(process.cwd()) + "." + config.tld;
328
396
  }
329
397
  function dirname() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litestar-vite-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Litestar plugin for Vite.",
5
5
  "keywords": [
6
6
  "litestar",