-
Has anyone already tried out/figured out how to use MDsveX with const { mdsvex } = require(`mdsvex`)
module.exports = {
adapter: `@sveltejs/adapter-static`,
preprocess: mdsvex(),
extensions: [`.svelte`, `.svx`],
} |
Beta Was this translation helpful? Give feedback.
Replies: 19 comments 6 replies
-
Something like that should work, yeah. I have not tested this yet though. |
Beta Was this translation helpful? Give feedback.
-
I'm missing something. If I try the above config and create the following file at
then start the dev server and navigate to http://localhost:3000/test, I get the following error
|
Beta Was this translation helpful? Give feedback.
-
Forgot to mention, I also tried this (as per the docs) but didn't work either: module.exports = {
extends: `@sveltejs/snowpack-config`,
installOptions: {
rollup: {
plugins: [
require(`rollup-plugin-svelte`)({
extensions: [`.svelte`, `.svx`],
preprocess: require(`mdsvex`).mdsvex(),
}),
],
},
},
} That threw
|
Beta Was this translation helpful? Give feedback.
-
I'm hitting the same thing. Preliminary findings:
return route.load().then(async (mod) => {
const handler = mod[request.method.toLowerCase().replace('delete', 'del')]; // 'delete' is a reserved word
if (handler) {
// ... very long success path omitted ...
} else {
return {
status: 501,
body: `${request.method} is not implemented for ${request.path}`,
headers: {}
};
}
I also found that the manifest looked different when I used the
By renaming index.svx to index.svelte, I was able to notice a difference in the First test, with import * as layout from "/_app/assets/components/layout.svelte";
const components = [
() => import("/_app/routes/index.svelte"),
() => import("/_app/routes/about/foo.svelte")
];
const d = decodeURIComponent;
const empty = () => ({});
export const pages = [
{
// index.svelte
pattern: /^\/$/,
params: empty,
parts: [components[0]]
},
{
// about/foo.svelte
pattern: /^\/about\/foo\/?$/,
params: empty,
parts: [components[1]]
}
];
export const ignore = [
/^\/about\/?$/
];
export { layout }; Second test, with import * as layout from "/_app/assets/components/layout.svelte";
const components = [
() => import("/_app/routes/index.svelte"),
() => import("/_app/routes/about/index.svelte"),
() => import("/_app/routes/about/foo.svelte")
];
const d = decodeURIComponent;
const empty = () => ({});
export const pages = [
{
// index.svelte
pattern: /^\/$/,
params: empty,
parts: [components[0]]
},
{
// about/index.svelte
pattern: /^\/about\/?$/,
params: empty,
parts: [components[1]]
},
{
// about/foo.svelte
pattern: /^\/about\/foo\/?$/,
params: empty,
parts: [components[2]]
}
];
export const ignore = [
];
export { layout }; The That's as far as I've gotten and I'm running out of time to investigate this today. But it looks like something is different about the manifest between having a .svelte extension and having an .svx extension, and that's causing this behavior. |
Beta Was this translation helpful? Give feedback.
-
Update: This appears to have nothing to do with mdsvex! I commented out the msdvex pre-processor in my svelte.config.js and the problem persisted. A bit more poking around led me to the create_manifest_data function in @svelte/kit's create_app.js file. Its first few lines are: function create_manifest_data(config, extensions = '.svelte') {
// TODO support .svelte.md etc?
const cwd = config.files.routes;
const component_extensions = extensions.split(' '); And it's called in two places in @svelte/kit, one in index.js and one in index2.js. The first call looks like this: update() {
const manifest_data = create_app.create_manifest_data(this.config);
create_app.create_app({
manifest_data,
output: '.svelte/assets'
}); And the second one looks like this: async function build(config) {
const manifest = create_app.create_manifest_data(config);
utils.mkdirp(ASSETS);
await rimraf(UNOPTIMIZED);
await rimraf(OPTIMIZED);
create_app.create_app({
manifest_data: manifest,
output: '.svelte/assets'
}); In both cases, no second parameter is given to create_app.create_manifest_data, so there's no way to override the |
Beta Was this translation helpful? Give feedback.
-
Thanks for this detailed report of your findings. Really excited for when the official docs for |
Beta Was this translation helpful? Give feedback.
-
My current approach (work with latest <!-- src/routes/index.svelte -->
<script>
// Router will ignore all files start with underscore,
// don't treat them as endpoint
import Index from './_Index.svx';
</script>
<Index /> // svelte.config.js
module.exports = {
extensions: [".svelte", ".svx"],
preprocess: [
mdsvex()
],
} Tested with |
Beta Was this translation helpful? Give feedback.
-
I use a similar approach, except I also want to write plain Markdown files as well. So I use // svelte.config.js
const sveltePreprocess = require('svelte-preprocess');
const { mdsvex } = require('mdsvex');
const mdsvex_config = {
extensions: ['.md', '.svx'],
}
module.exports = {
extensions: ['.svelte', ...mdsvex_config.extensions],
preprocess: [
sveltePreprocess(),
mdsvex(mdsvex_config),
],
kit: {
adapter: '@sveltejs/adapter-node',
target: '#svelte'
}
}; The extra Then I add a mount location and import alias for // snowpack.config.js
module.exports = {
extends: '@sveltejs/snowpack-config',
plugins: ['@snowpack/plugin-typescript'],
mount: {
'src/components': '/_components',
'src/pages': '/_pages'
},
alias: {
$components: './src/components',
$pages: './src/pages'
}
}; And then the boilerplate route file: <!-- src/routes/about.svelte -->
<script>
import About from '$pages/about.md'
</script>
<About/> |
Beta Was this translation helpful? Give feedback.
-
Has anyone here managed to get |
Beta Was this translation helpful? Give feedback.
-
Yeah, would be great to have an example for SvelteKit! |
Beta Was this translation helpful? Give feedback.
-
Hi @jamesb93 and @mhatvan I started with ts+scss template. const sveltePreprocess = require('svelte-preprocess');
const adapter = require('@sveltejs/adapter-node');
const pkg = require('./package.json');
const { mdsvex } = require(`mdsvex`);
const extensions = [`.svelte`, '.md', `.mdx`, '.svx']
/** @type {import('@sveltejs/kit').Config} */
module.exports = {
preprocess:
[
sveltePreprocess(),
mdsvex({ extensions: extensions }),
],
extensions: extensions,
kit: {
adapter: adapter(),
target: '#svelte', // hydrate the <div id="svelte"> element in src/app.html
vite: {
ssr: {
noExternal: Object.keys(pkg.dependencies || {})
}
}
}
}; |
Beta Was this translation helpful? Give feedback.
-
@DrMagPie yeah that most likely works for an import of e.g. |
Beta Was this translation helpful? Give feedback.
-
I've converted this into a discussion as I think it will be valuable for others users trying to do the same! I'll be putting together a kit & mdsvex example very soon, and will update as soon as I have it working. If people have some example sapper apps that I can take a look at, I'd love to see the sort of thing that people are doing with mdsvex and sapper, so I can try to cover the common cases. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Haven't tried it myself yet but this might be helpful: https://github.com/svelte-add/mdsvex. Linked by the official SvelteKit docs. |
Beta Was this translation helpful? Give feedback.
-
I just tried it today, and it Just Works™: // svelte.config.cjs
const { mdsvex } = require(`mdsvex`)
module.exports = {
extensions: ['.svelte', '.svx'],
preprocess: [ mdsvex() ],
// kit: { ... } omitted for brevity (unchanged from default)
}; With that svelte.config.cjs file, I can create <script context="module">
export function load({ page }) {
const { slug } = page.params;
if (slug) {
return { props: { title: slug }};
}
}
</script>
<script>
import Counter from '$lib/Counter.svelte';
export let title;
</script>
# Blog post
Title from URL: {title}
This page is written in Markdown. Here's some **bold** and *italic* to prove it.
And here's a counter, too: <Counter/> and it's inline. So with the current version of Svelte-Kit ( |
Beta Was this translation helpful? Give feedback.
-
See https://github.com/rmunn/svelte-kit-mdsvex-example to see this all working just as expected. |
Beta Was this translation helpful? Give feedback.
-
Slightly off topic but perhaps interesting to people here: I started a new repo https://github.com/janosh/awesome-svelte-kit to collect excellent SvelteKit sites in production that might serve as learning resources and/or inspiration. Everyone feel free to submit PRs for sites you've come across that you think should be added to the list, even if it's your own site. The site should be open source and fully production ready. |
Beta Was this translation helpful? Give feedback.
-
Hello guys, did anyone try it with compile function imported from mdsvex instead of .svx file? |
Beta Was this translation helpful? Give feedback.
-
Note for myself. If you want configure mdsevx with the last version of svelte kit with vite import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
import { mdsvex } from 'mdsvex';
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', '.svx'],
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [preprocess(), mdsvex()],
//preprocess: mdsvex(),
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: null
})
}
};
export default config; |
Beta Was this translation helpful? Give feedback.
I just tried it today, and it Just Works™:
With that svelte.config.cjs file, I can create
src/routes/blogpost.svx
and it Just Works. I was also able to createsrc/routes/[slug].svx
and it was handled correctly too: