Replies: 3 comments 2 replies
-
Is there a way to resolve imports from the server side? I'm loading <script context="module">
export async function load() {
const mdsvex = await import('mdsvex');
const compiled = await mdsvex.compile(
`
<script>
import Chart from './Chart.svelte';
</script>
# Hello friends
<Chart />
`,
{},
);
return {
props: {
compiled,
},
};
}
</script>
<script lang="ts">
export let compiled = {};
</script>
{@html compiled.code} I used next-mdx-remote, and my current expectation with |
Beta Was this translation helpful? Give feedback.
-
Seeing this discussion, I'm going to bump it as I'm running into the same set of questions. I have a CMS with some markdown functionality and am trying to see if I can render it using mdsvex, because it would be cool to write svelte components in the markdown from the CMS. The problem is basically how to render this out dynamically on the server, ideally as a string of html. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone 👋
I have a question regarding not using the local ".mds" files approach which I couldn't find any good explanation and it seems it might be a misunderstanding from myself of how Vite + sveltekit + mdsvex works altogether.
I'm sorry if this discussion is too long but I'll try to give as many details as I can so you can understand and see what detail is missing.
Please let me know if this isn't clear enough.
The problem
Almost all examples I find here, on YouTube, courses that talk about MDX using
mdsvex
are based on local files.I currently have a blog/website in NextJS which loads
mdx
from a CMS (strapi) and renders using a package callednext-mdx-remote
.Long story short, it does the same thing as
mdsvex
does with the same API but it does server (SSG) / client (hydration) work, but the configuration is pretty similar.I currently host this website on
Vercel
and do it viaSSG
+ Lambda function, which thesveltekit-adapter/vercel
handles pretty well.Attempts to solve the problem
Here is some stuff I tried out. The second attempt did the job but it feels... hacky.
Also, I didn't stress it out enough with some
remark
/rehype
plugins I currently use, which can also cause some issues but it's another topic.Attempt 1: compile via `load` function
My first attempt was by, in a
routes/blog/[index].svelte
page, emulates the compilation there:But by doing that, it renders correctly server-side and I can see the first render on the screen with the data but right after it throws an error in the server:
Attempt 2: importing `mdsvex/dist/umd` module (it works but...)
I read somewhere someone suggesting to import
mdsvex/dist/browser-umd
instead.This works just fine for both
dev
andpreview
mode but it throws a warning of a huge chunk:It makes sense because the lib itself has ~500kb.
Final thoughts
What do you think about that? Is this the correct approach? Have you solved this problem differently? Is there some Vite configuration I should do to solve that?
Thanks for reading :)
Resources
Beta Was this translation helpful? Give feedback.
All reactions