Add support for MDX (#17)

* feat: add support for MDX

* fix: prevent empty server handler error message

* doc: add MDX mention to README

* feat: update version to v0.7.0
This commit is contained in:
Valerio Ageno
2024-07-22 07:59:43 +02:00
committed by GitHub
parent 2949ea4dfa
commit 444d1479b0
27 changed files with 318 additions and 19 deletions
@@ -46,7 +46,7 @@ async function getRouteNodes(
if (dirent.isDirectory()) {
await recurse(relativePath)
} else if (fullPath.match(/\.(tsx|ts|jsx|js)$/)) {
} else if (fullPath.match(/\.(tsx|ts|jsx|js|mdx)$/)) {
const filePath = replaceBackslash(path.join(dir, dirent.name))
const filePathNoExt = removeExt(filePath)
let routePath =
@@ -220,6 +220,7 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
const imports = [
...sortedRouteNodes.map((node) => {
const extension = node.filePath.endsWith('mdx') ? '.mdx' : ''
return `const ${
node.variableName
}Import = dynamic(() => import('./${replaceBackslash(
@@ -230,7 +231,7 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
),
false,
),
)}'))`
)}${extension}'))`
}),
].join('\n')