feat: support auto gen and support alias

This commit is contained in:
Joel 2025-11-13 17:14:01 +08:00
parent 1e127df4ab
commit 7a2e951474
7 changed files with 58 additions and 10 deletions

View File

@ -12,6 +12,8 @@ import GotoAnything from '@/app/components/goto-anything'
import Zendesk from '@/app/components/base/zendesk'
import Splash from '../components/splash'
import Test from '@edition/test'
import SubSubIndex from '@edition/sub/sub-sub/index'
import SubSub from '@edition/sub/sub-sub'
const Layout = ({ children }: { children: ReactNode }) => {
return (
@ -23,6 +25,8 @@ const Layout = ({ children }: { children: ReactNode }) => {
<ProviderContextProvider>
<ModalContextProvider>
<Test />
<SubSubIndex />
<SubSub />
<HeaderWrapper>
<Header />
</HeaderWrapper>

View File

View File

@ -0,0 +1,12 @@
'use client'
import type { FC } from 'react'
import React from 'react'
const SubSub: FC = () => {
return (
<div>
Sub Sub
</div>
)
}
export default React.memo(SubSub)

View File

View File

View File

@ -1,4 +1,5 @@
const { codeInspectorPlugin } = require('code-inspector-plugin')
const fs = require('fs')
const path = require('path')
const withPWA = require('next-pwa')({
dest: 'public',
@ -88,12 +89,42 @@ const hasSetWebPrefix = process.env.NEXT_PUBLIC_WEB_PREFIX
const port = process.env.PORT || 3000
const locImageURLs = !hasSetWebPrefix ? [new URL(`http://localhost:${port}/**`), new URL(`http://127.0.0.1:${port}/**`)] : []
const remoteImageURLs = [hasSetWebPrefix ? new URL(`${process.env.NEXT_PUBLIC_WEB_PREFIX}/**`) : '', ...locImageURLs].filter(item => !!item)
const editionPath =
process.env.NEXT_PUBLIC_EDITION === 'CLOUD'
? './app/edition/saas/test.tsx'
: './app/edition/community/test.tsx'
path.resolve(__dirname, editionPath, '*')
console.log(editionPath)
const isSaaS = process.env.NEXT_PUBLIC_EDITION === 'CLOUD'
const supportPostfixReg = /\.(ts|tsx|css|svg|jpg|jpeg|png)$/
const editionPaths = (() => {
const editionDir = `./app/edition/${isSaaS ? 'saas' : 'community'}`
const result = {}
function walk(dir) {
const files = fs.readdirSync(dir)
for (const file of files) {
const fullPath = path.join(dir, file)
const stat = fs.statSync(fullPath)
if (stat.isDirectory()) {
walk(fullPath)
} else if (supportPostfixReg.test(file)) {
const relPath = path.relative(editionDir, fullPath)
const key = `@edition/${relPath.replace(/\\/g, '/')}`.replace(/\.(ts|tsx|css)$/, '')
const fullPathWithoutPrefix = `./${fullPath.replace(supportPostfixReg, '')}`
result[key] = fullPathWithoutPrefix
if (key.endsWith('/index')) {
const dirKey = key.replace(/\/index$/, '')
result[dirKey] = fullPathWithoutPrefix
}
}
}
}
if (fs.existsSync(editionDir)) {
walk(editionDir)
}
return result
})()
console.log(JSON.stringify(editionPaths, null, 2))
/** @type {import('next').NextConfig} */
const nextConfig = {
@ -103,9 +134,9 @@ const nextConfig = {
rules: codeInspectorPlugin({
bundler: 'turbopack'
}),
// resolveAlias: {
// '@edition/test': editionPath,
// }
resolveAlias: {
...editionPaths,
}
},
productionBrowserSourceMaps: false, // enable browser source map generation during the production build
// Configure pageExtensions to include md and mdx

View File

@ -31,7 +31,8 @@
"./*"
],
"@edition/*": [
"./app/edition/community/*"
"./app/edition/saas/*",
"./app/edition/community/*",
]
}
},