Skip to content

Commit 7fd50fa

Browse files
committed
feat(entries): expose entries
1 parent 74ff55a commit 7fd50fa

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

packages/entries/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-conventional-entries",
3-
"version": "1.0.0-beta.0",
3+
"version": "1.0.0-beta.1",
44
"description": "vite plugin to generate conventional entries",
55
"keywords": [
66
"vite",

packages/entries/shim.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'virtual:conventional-entries' {
2+
export interface Entry {
3+
entryPath: string;
4+
routePath: string;
5+
serverPath: string;
6+
htmlPath: string;
7+
}
8+
9+
const entries: Entry[];
10+
export default entries;
11+
}

packages/entries/src/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export const DEFAULT_HTML_PATH = path.resolve(__dirname, '../default.html');
55
export const DEFAULT_ENTRY_MODULE_ID =
66
'/@conventional-entries/default-entry.jsx';
77

8+
// entries module id
9+
export const ENTRIES_MODULE_ID = 'virtual:conventional-entries';
10+
export const RESOLVED_ENTRIES_MODULE_ID = '\0' + ENTRIES_MODULE_ID;
11+
812
export const HEAD_INJECT_RE = /([ \t]*)<\/head>/i;
913
export const HEAD_PREPEND_INJECT_RE = /([ \t]*)<head[^>]*>/i;
1014

packages/entries/src/index.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import fg from 'fast-glob';
55
import mm from 'micromatch';
66
import { Entry, UserConfig, UserEntryConfigItem } from './types';
77
import { flattenPath, normalizeRoutePath, toArray } from './utils';
8-
import { DEFAULT_ENTRY_MODULE_ID, DEFAULT_HTML_PATH } from './constants';
8+
import {
9+
DEFAULT_ENTRY_MODULE_ID,
10+
DEFAULT_HTML_PATH,
11+
ENTRIES_MODULE_ID,
12+
RESOLVED_ENTRIES_MODULE_ID,
13+
} from './constants';
914
import {
1015
minifyHtml,
1116
prettifyHtml,
@@ -15,7 +20,11 @@ import {
1520

1621
export * from './types';
1722

18-
export { DEFAULT_ENTRY_MODULE_ID };
23+
export {
24+
DEFAULT_ENTRY_MODULE_ID,
25+
ENTRIES_MODULE_ID,
26+
RESOLVED_ENTRIES_MODULE_ID,
27+
};
1928

2029
function getHtmlOutDir(root: string) {
2130
const nodeModulesDir = path.resolve(root, 'node_modules');
@@ -181,7 +190,12 @@ export function conventionalEntries(userConfig: UserConfig = {}): Plugin[] {
181190
entries: userEntries.flatMap(({ dir, pattern }) =>
182191
toArray(pattern).map(p => `${path.relative(root, dir)}/${p}`)
183192
),
184-
include: ['react', 'react-dom/client'],
193+
include: [
194+
'react',
195+
'react/jsx-runtime',
196+
'react/jsx-dev-runtime',
197+
'react-dom/client',
198+
],
185199
},
186200
build: {
187201
rollupOptions: {
@@ -301,6 +315,21 @@ if (rootEl) {
301315
}
302316
},
303317
},
318+
{
319+
name: 'vite-plugin-conventional-entries:expose-entries',
320+
resolveId(source) {
321+
if (source === ENTRIES_MODULE_ID) {
322+
return RESOLVED_ENTRIES_MODULE_ID;
323+
}
324+
},
325+
load(id) {
326+
if (id === RESOLVED_ENTRIES_MODULE_ID) {
327+
return `export const entries = ${JSON.stringify(entries, null, 2)};
328+
export default entries;
329+
`;
330+
}
331+
},
332+
},
304333
];
305334
}
306335

0 commit comments

Comments
 (0)