feat: Introduce SSG

This commit is contained in:
deytenit committed 2026-02-15 18:48:51 +03:00
1 parent 7fd11d2220
commit 0784e0b305
13 files changed
+157 -47

No files matched your search

@@ -0,0 +1,27 @@
import { join } from 'node:path';
import fg from 'fast-glob';
export function discoverEntries(root: string, pattern: string): Record<string, string> {
const files = fg.sync(pattern, { cwd: root });
const entries: Record<string, string> = {};
for (const file of files) {
// We expect the user to provide a pattern like './src/app/*.tsx'
// We'll strip the directory parts to get the name
const parts = file.split('/');
// Remove extension from the last part
const filename = parts[parts.length - 1].replace(/\.tsx$/, '');
// For nested routes, we might want to keep the path but relative to the app root
// But since you want 'index', 'articles/index', etc.
// Let's just use the file path relative to the common root 'src/app' if it exists in the path
const appMatch = file.match(/src\/app\/(.*)\.tsx$/);
let name = appMatch ? appMatch[1] : filename;
name = name.replace(/\/index$/, '') || 'index';
entries[name] = join(root, file);
}
return entries;
}
@@ -1,2 +1,3 @@
export * from './rsbuild.js';
export * from './vitest.js';
export * from './entries.js';
@@ -22,6 +22,17 @@ export function defineServiceConfig(config: RsbuildConfig = {}): RsbuildConfig {
plugins: [pluginReact(), pluginTypeCheck()],
html: {
template: './src/static/index.html',
tags: [
{
tag: 'style',
children: `
:root { background-color: #f6f6f6; color: #262626; }
.dark { background-color: #262626; color: #f6f6f6; }
body { margin: 0; transition: background-color 0.2s ease; }
`,
head: true,
},
],
},
...config,
});
@@ -0,0 +1,17 @@
import type { RsbuildPlugin } from '@rsbuild/core';
/**
* A minimal Rsbuild plugin for build-time Static Site Generation.
* Placeholder for future extension.
*/
export function ssgPlugin(): RsbuildPlugin {
return {
name: 'ermnvldmr:ssg-plugin',
setup(api) {
api.onAfterBuild(async ({ stats }) => {
if (!stats) return;
console.log('[ssg-plugin] Build finished.');
});
},
};
}