Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build): dist entries file #1292

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/waku/src/lib/builder/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from '../utils/path.js';
import { extendViteConfig } from '../utils/vite-config.js';
import {
appendFile,
copyFile,
createWriteStream,
existsSync,
Expand Down Expand Up @@ -629,11 +628,18 @@ const emitStaticFiles = async (
}
await waitForTasks();
const dynamicHtmlPaths = Array.from(dynamicHtmlPathMap);
const code = `
export const dynamicHtmlPaths = ${JSON.stringify(dynamicHtmlPaths)};
export const publicIndexHtml = ${JSON.stringify(defaultHtmlStr)};
`;
await appendFile(distEntriesFile, code);
let distEntriesFileContent = await readFile(distEntriesFile, {
encoding: 'utf8',
});
distEntriesFileContent = distEntriesFileContent.replace(
'globalThis.__WAKU_DYNAMIC_HTML_PATHS__',
JSON.stringify(dynamicHtmlPaths),
);
distEntriesFileContent = distEntriesFileContent.replace(
'globalThis.__WAKU_PUBLIC_INDEX_HTML__',
JSON.stringify(defaultHtmlStr),
);
await writeFile(distEntriesFile, distEntriesFileContent);
};

// For Deploy
Expand Down
13 changes: 9 additions & 4 deletions packages/waku/src/lib/builder/platform-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INTERNAL_iterateSerializablePlatformData } from '../../server.js';
import { joinPath } from '../utils/path.js';
import { appendFile, mkdir, writeFile } from '../utils/node-fs.js';
import { mkdir, readFile, writeFile } from '../utils/node-fs.js';
import { DIST_ENTRIES_JS } from './constants.js';

const DIST_PLATFORM_DATA = 'platform-data';
Expand All @@ -15,10 +15,14 @@ export const emitPlatformData = async (distDir: string) => {
const destFile = joinPath(distDir, DIST_PLATFORM_DATA, key + '.js');
await writeFile(destFile, `export default ${JSON.stringify(data)};`);
}
await appendFile(
joinPath(distDir, DIST_ENTRIES_JS),
const distEntriesFile = joinPath(distDir, DIST_ENTRIES_JS);
let distEntriesFileContent = await readFile(distEntriesFile, {
encoding: 'utf8',
});
distEntriesFileContent = distEntriesFileContent.replace(
'globalThis.__WAKU_LOAD_PLATFORM_DATA__',
`
export function loadPlatformData(key) {
(key) => {
switch (key) {
${Array.from(keys)
.map(
Expand All @@ -31,4 +35,5 @@ export function loadPlatformData(key) {
}
`,
);
await writeFile(distEntriesFile, distEntriesFileContent);
};
3 changes: 3 additions & 0 deletions packages/waku/src/lib/plugins/vite-plugin-rsc-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export function loadModule(id) {
}
globalThis.__WAKU_SERVER_IMPORT__ = loadModule;
globalThis.__WAKU_CLIENT_IMPORT__ = (id) => loadModule('${opts.ssrDir}/' + id);
export const dynamicHtmlPaths = globalThis.__WAKU_DYNAMIC_HTML_PATHS__;
export const publicIndexHtml = globalThis.__WAKU_PUBLIC_INDEX_HTML__;
export const loadPlatformData = globalThis.__WAKU_LOAD_PLATFORM_DATA__;
`;
let entriesFile = '';
let configFile = '';
Expand Down
Loading