vite-plugin-htjs-pages 0.5.0 → 0.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-htjs-pages",
3
3
  "author": "Paul Browne",
4
- "version": "0.5.0",
4
+ "version": "0.5.2",
5
5
  "type": "module",
6
6
  "description": "Small HT.js pages plugin for Vite with dynamic routes, catch-all routes, and static params",
7
7
  "main": "./dist/index.js",
package/src/dev-server.ts CHANGED
@@ -5,7 +5,7 @@ import type { HtPageInfo, HtPageModule } from './types';
5
5
 
6
6
  export function installDevServer(args: {
7
7
  server: ViteDevServer;
8
- getPages: () => HtPageInfo[];
8
+ getPages: () => Promise<HtPageInfo[]>;
9
9
  }): void {
10
10
  const { server, getPages } = args;
11
11
 
@@ -13,7 +13,7 @@ export function installDevServer(args: {
13
13
  if (!req.url || req.method !== 'GET') return next();
14
14
 
15
15
  const pathname = req.url.split('?')[0];
16
- const pages = getPages();
16
+ const pages = await getPages();
17
17
 
18
18
  for (const page of pages) {
19
19
  const params = routeMatch(page.routePattern, pathname);
package/src/plugin.ts CHANGED
@@ -62,14 +62,15 @@ export function htPages(options: HtPagesPluginOptions = {}): Plugin {
62
62
  return {
63
63
  name: 'vite-plugin-htjs-pages',
64
64
 
65
- config(userConfig) {
65
+ config(userConfig, env) {
66
+ if (env.command !== 'build') return;
67
+
66
68
  const hasExplicitInput =
67
69
  userConfig.build?.rollupOptions?.input != null;
68
-
70
+
69
71
  if (hasExplicitInput) return;
70
-
72
+
71
73
  return {
72
- appType: 'custom',
73
74
  build: {
74
75
  rollupOptions: {
75
76
  input: VIRTUAL_BUILD_ENTRY_ID,
@@ -106,7 +107,10 @@ export function htPages(options: HtPagesPluginOptions = {}): Plugin {
106
107
 
107
108
  installDevServer({
108
109
  server,
109
- getPages: () => devPages,
110
+ getPages: async () => {
111
+ if (devPages.length > 0) return devPages;
112
+ return await loadDevPages();
113
+ },
110
114
  });
111
115
 
112
116
  loadDevPages().catch((error) => {