fix, feat, doc: massive build system refactorion, bug fixes and apex documentation (#19)
This commit is contained in:
1 parent
e8b42c60c2
commit
91f5245823
165 files changed
+8598
-1205
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import { defineServiceConfig, discoverEntries, mergeConfig } from '@ermnvldmr/rsbuild-config/dev';
|
||||
import { createReadStream, existsSync } from 'node:fs';
|
||||
import { extname, join, sep } from 'node:path';
|
||||
import { defineSSGServiceConfig, discoverEntries, mergeConfig } from '@ermnvldmr/ssg/dev';
|
||||
import { THEME_INIT_SCRIPT, THEME_INIT_STYLES } from '@ermnvldmr/ui/dev';
|
||||
import { localeRsbuildConfig } from '@ermnvldmr/i18n/dev';
|
||||
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
||||
@@ -6,11 +8,56 @@ import { pluginMdx } from '@rsbuild/plugin-mdx';
|
||||
import remarkFrontmatter from 'remark-frontmatter';
|
||||
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
|
||||
|
||||
const MIME: Record<string, string> = {
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.png': 'image/png',
|
||||
'.gif': 'image/gif',
|
||||
'.webp': 'image/webp',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.avif': 'image/avif',
|
||||
'.ico': 'image/x-icon',
|
||||
'.woff': 'font/woff',
|
||||
'.woff2': 'font/woff2',
|
||||
'.ttf': 'font/ttf',
|
||||
'.css': 'text/css',
|
||||
'.js': 'application/javascript',
|
||||
'.json': 'application/json',
|
||||
'.txt': 'text/plain',
|
||||
};
|
||||
|
||||
const locale = process.env.LOCALE ?? 'en';
|
||||
const fontBase = `/${locale}/static/font`;
|
||||
|
||||
export default defineServiceConfig(
|
||||
export default defineSSGServiceConfig(
|
||||
mergeConfig(localeRsbuildConfig(), {
|
||||
dev: {
|
||||
// Serve public/static/* at /static/* directly, bypassing server.base.
|
||||
// Without this, server.base (e.g. /en) would push the public dir to
|
||||
// /en/static/*, making /static/* unreachable in dev.
|
||||
setupMiddlewares: [
|
||||
(middlewares) => {
|
||||
middlewares.unshift((req, res, next) => {
|
||||
const url = (req as { url?: string }).url ?? '';
|
||||
if (!url.startsWith('/static/')) return next();
|
||||
|
||||
// Strip the leading slash so the '/static/...' segment is treated as
|
||||
// relative to public/ (an absolute segment would otherwise let a
|
||||
// resolved path escape it), then confine the result to public/ to
|
||||
// block '..' path traversal.
|
||||
const publicDir = join(import.meta.dirname, 'public');
|
||||
const requestedPath = (url.split('?')[0] ?? url).replace(/^\/+/, '');
|
||||
const filePath = join(publicDir, requestedPath);
|
||||
if (!filePath.startsWith(publicDir + sep) || !existsSync(filePath)) return next();
|
||||
|
||||
const mime = MIME[extname(filePath)] ?? 'application/octet-stream';
|
||||
res.setHeader('Content-Type', mime);
|
||||
createReadStream(filePath).pipe(res as import('node:stream').Writable);
|
||||
});
|
||||
return middlewares;
|
||||
},
|
||||
],
|
||||
},
|
||||
tools: {
|
||||
rspack: {
|
||||
plugins: [
|
||||
@@ -31,6 +78,7 @@ export default defineServiceConfig(
|
||||
],
|
||||
source: {
|
||||
entry: discoverEntries(import.meta.dirname, './src/app/**/*.tsx'),
|
||||
preEntry: ['./src/static/global.css'],
|
||||
},
|
||||
html: {
|
||||
tags: [
|
||||
|
||||
Reference in new issue
Block a user