Skip to content

Commit 7a334cc

Browse files
committed
fix: compatible for other loaders
1 parent 4c97ab6 commit 7a334cc

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { codeInspectorPlugin } from 'code-inspector-plugin';
22
import type { NextConfig } from 'next';
3-
import createMDX from '@next/mdx'
3+
import createMDX from '@next/mdx';
44

55
const withMDX = createMDX({
6-
// Add markdown plugins here, as desired
7-
})
6+
extension: /\.(md|mdx)$/,
7+
});
88

99
const nextConfig: NextConfig = {
1010
pageExtensions: ['js', 'jsx', 'md', 'mdx', 'ts', 'tsx'],
@@ -15,4 +15,4 @@ const nextConfig: NextConfig = {
1515
},
1616
};
1717

18-
export default withMDX(nextConfig)
18+
export default withMDX(nextConfig);

demos/turbopack-next15/src/app/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import Image from "next/image";
1+
import Image from 'next/image';
2+
import Welcome from './welcome.mdx';
23

34
export default function Home() {
45
return (
56
<div className="font-sans grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20">
7+
<Welcome />
68
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start">
79
<Image
810
className="dark:invert"
@@ -14,7 +16,7 @@ export default function Home() {
1416
/>
1517
<ol className="font-mono list-inside list-decimal text-sm/6 text-center sm:text-left">
1618
<li className="mb-2 tracking-[-.01em]">
17-
Get started by editing{" "}
19+
Get started by editing{' '}
1820
<code className="bg-black/[.05] dark:bg-white/[.06] font-mono font-semibold px-1 py-0.5 rounded">
1921
src/app/page.tsx
2022
</code>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Welcome to my MDX page!
2+
3+
This is some **bold** and _italics_ text.
4+
5+
This is a list in markdown:
6+
7+
- One
8+
- Two
9+
- Three
10+
11+
Checkout my React component:

packages/core/src/server/transform/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs';
12
import { transformJsx } from './transform-jsx';
23
import { transformSvelte } from './transform-svelte';
34
import { transformVue } from './transform-vue';
@@ -31,12 +32,18 @@ const CodeInspectorEscapeTags = [
3132
];
3233

3334
export function transformCode(params: TransformCodeParams) {
34-
let { content, filePath, fileType, escapeTags = [], pathType = 'relative' } = params;
35-
const finalEscapeTags = [
36-
...CodeInspectorEscapeTags,
37-
...escapeTags,
38-
];
39-
35+
let {
36+
content,
37+
filePath,
38+
fileType,
39+
escapeTags = [],
40+
pathType = 'relative',
41+
} = params;
42+
if (!fs.existsSync(filePath)) {
43+
return content;
44+
}
45+
const finalEscapeTags = [...CodeInspectorEscapeTags, ...escapeTags];
46+
4047
filePath = getRelativeOrAbsolutePath(filePath, pathType);
4148

4249
try {

packages/core/src/server/use-client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ export async function getCodeWithWebComponent({
309309
code: string;
310310
inject?: boolean;
311311
}) {
312+
if (!fs.existsSync(file)) {
313+
return code;
314+
}
312315
// start server
313316
if (options.behavior?.locate !== false) {
314317
await startServer(options, record);

0 commit comments

Comments
 (0)