vite-plugin-htjs-pages 0.3.0 → 0.4.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/plugin.ts +37 -21
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.3.0",
4
+ "version": "0.4.0",
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.cjs",
@@ -19,7 +19,7 @@
19
19
  "typecheck": "tsc --noEmit"
20
20
  },
21
21
  "peerDependencies": {
22
- "vite": "^5 || ^6"
22
+ "vite": ">=5"
23
23
  },
24
24
  "dependencies": {
25
25
  "fast-glob": "^3.3.3",
package/src/plugin.ts CHANGED
@@ -10,6 +10,8 @@ import { buildRenderBundle } from './render-bundle';
10
10
  import { renderPage } from './render-runtime';
11
11
  import type { HtPageInfo, HtPageModule, HtPagesPluginOptions } from './types';
12
12
 
13
+ const VIRTUAL_BUILD_ENTRY_ID = '\0vite-plugin-ht-pages:build-entry';
14
+
13
15
  function chunkArray<T>(items: T[], size: number): T[][] {
14
16
  const out: T[][] = [];
15
17
  for (let i = 0; i < items.length; i += size) {
@@ -34,10 +36,7 @@ async function importManifest(bundlePath: string): Promise<Array<{ page: HtPageI
34
36
  export function htPages(options: HtPagesPluginOptions = {}): Plugin {
35
37
  let root = process.cwd();
36
38
  let server: ViteDevServer | null = null;
37
- let config: ResolvedConfig;
38
39
  let devPages: HtPageInfo[] = [];
39
- let cachedManifestKey: string | null = null;
40
- let cachedBundlePath: string | null = null;
41
40
  const cleanUrls = options.cleanUrls ?? true;
42
41
 
43
42
  async function loadDevPages(): Promise<HtPageInfo[]> {
@@ -61,10 +60,37 @@ export function htPages(options: HtPagesPluginOptions = {}): Plugin {
61
60
  }
62
61
 
63
62
  return {
64
- name: 'vite-plugin-htjs-pages',
63
+ name: 'vite-plugin-ht-pages',
64
+
65
+ config(userConfig) {
66
+ const hasExplicitInput =
67
+ userConfig.build?.rollupOptions?.input != null;
68
+
69
+ if (hasExplicitInput) return;
70
+
71
+ return {
72
+ appType: 'custom',
73
+ build: {
74
+ rollupOptions: {
75
+ input: VIRTUAL_BUILD_ENTRY_ID,
76
+ },
77
+ },
78
+ };
79
+ },
80
+
81
+ resolveId(id) {
82
+ if (id === VIRTUAL_BUILD_ENTRY_ID) return id;
83
+ return null;
84
+ },
85
+
86
+ load(id) {
87
+ if (id === VIRTUAL_BUILD_ENTRY_ID) {
88
+ return 'export default {};';
89
+ }
90
+ return null;
91
+ },
65
92
 
66
93
  configResolved(resolved) {
67
- config = resolved;
68
94
  root = resolved.root;
69
95
  },
70
96
 
@@ -101,22 +127,12 @@ export function htPages(options: HtPagesPluginOptions = {}): Plugin {
101
127
 
102
128
  async generateBundle() {
103
129
  const entries = await discoverEntryPages(root, options);
104
- const cacheDir = path.join(root, 'node_modules/.cache/vite-plugin-htjs-pages');
105
-
106
- const entriesKey = createEntriesKey(entries);
107
-
108
- let bundlePath: string;
109
- if (cachedBundlePath && cachedManifestKey === entriesKey) {
110
- bundlePath = cachedBundlePath;
111
- } else {
112
- bundlePath = await buildRenderBundle({
113
- entries,
114
- cacheDir,
115
- ssrPlugins: options.ssrPlugins,
116
- });
117
- cachedManifestKey = entriesKey;
118
- cachedBundlePath = bundlePath;
119
- }
130
+ const cacheDir = path.join(root, 'node_modules/.cache/vite-plugin-ht-pages');
131
+ const bundlePath = await buildRenderBundle({
132
+ entries,
133
+ cacheDir,
134
+ ssrPlugins: options.ssrPlugins,
135
+ });
120
136
 
121
137
  const manifest = await importManifest(bundlePath);
122
138
  const modulesByEntry = new Map<string, HtPageModule>();