You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I hope this supports the Contentlayer project and helps to enlarge the Svelte / Contentlayer community.
Given a repository that's prepared to import/render the contentlayer content, would a Vite plugin work? All it does is invoke contentlayer build and contentlayer dev during the Vite lifecycle.
// vite.config.js// @ts-checkimport*ascorefrom'@contentlayer/core'import{fs,errorToString}from'@contentlayer/utils'import{E,OT,pipe,S,T}from'@contentlayer/utils/effect'import{sveltekit}from'@sveltejs/kit/vite'import{defineConfig}from'vite'exportdefaultdefineConfig({plugins: [sveltekit(),contentlayer(),],})/** * @typedef {{ * clearCache?: boolean * configPath?: string | undefined * verbose?: boolean * isDev?: boolean * contentDirPath?: string * generatedDirPath?: string * }} ContentlayerOptions *//** * Contentlayer Vite plugin. * @param {ContentlayerOptions?} options * @returns {import('vite').Plugin} */functioncontentlayer(options=null){constresolvedOptions={generatedDirPath: '.contentlayer',contentDirPath: 'content',clearCache: false,configPath: undefined,verbose: false,isDev: true,
...options,}/** * @type {ReturnType<typeof startContentlayerDevelopmentWatch>} */letcontentLayerWatcher/** * @see https://github.com/contentlayerdev/contentlayer/blob/main/packages/%40contentlayer/cli/src/commands/DevCommand.ts */conststartContentlayerDevelopmentWatch=async()=>{/** * Promise that runs in the background while the server is running. * TODO: terminate gracefully when the server is stopped. */pipe(pipe(S.fromEffect(T.gen(function*($){if(resolvedOptions.clearCache){constcwd=yield*$(core.getCwd)constartifactsDir=core.ArtifactsDir.getDirPath({ cwd })yield*$(fs.rm(artifactsDir,{recursive: true,force: true}))yield*$(T.log('Cache cleared successfully'))}}),),S.chain(()=>core.getConfigWatch({configPath: resolvedOptions.configPath})),S.tapSkipFirstRight(()=>T.log(`Contentlayer config change detected. Updating type definitions and data...`),),S.tapRight((config)=>config.source.options.disableImportAliasWarning ? T.unit : T.fork(core.validateTsconfig),),S.chainSwitchMapEitherRight((config)=>core.generateDotpkgStream({
config,verbose: resolvedOptions.verbose,isDev: resolvedOptions.isDev,}),),S.tap(E.fold((error)=>T.log(errorToString(error)),core.logGenerateInfo)),OT.withStreamSpan('@contentlayer/cli/commands/DevCommand:stream'),S.runDrain,OT.withSpan('@contentlayer/cli/commands/DevCommand:executeSafe'),),core.runMain({tracingServiceName: 'contentlayer-cli',verbose: resolvedOptions.verbose||process.env['CL_DEBUG']!==undefined,}),)}/** * @see https://github.com/contentlayerdev/contentlayer/blob/main/packages/%40contentlayer/cli/src/commands/BuildCommand.ts */constbuildContentlayer=async()=>{returnpipe(pipe(T.gen(function*($){if(resolvedOptions.clearCache){constcwd=yield*$(core.getCwd)constartifactsDir=core.ArtifactsDir.getDirPath({ cwd })yield*$(fs.rm(artifactsDir,{recursive: true,force: true}))yield*$(T.log('Cache cleared successfully'))}}),T.chain(()=>core.getConfig({configPath: resolvedOptions.configPath})),T.tap((config)=>config.source.options.disableImportAliasWarning ? T.unit : T.fork(core.validateTsconfig),),T.chain((config)=>core.generateDotpkg({ config,verbose: resolvedOptions.verbose})),T.tap(core.logGenerateInfo),OT.withSpan('@contentlayer/cli/commands/BuildCommand:executeSafe'),),core.runMain({tracingServiceName: 'contentlayer-cli',verbose: resolvedOptions.verbose||process.env['CL_DEBUG']!==undefined,}),)}return{name: 'vite-plugin-contentlayer',/** * Add additional directories to the Vite server's file serving list. */asyncconfig(){return{server: {fs: {allow: [resolvedOptions.contentDirPath,resolvedOptions.generatedDirPath],},},}},/** * When development server starts, start contentlayer development watch. */asyncconfigureServer(){contentLayerWatcher=startContentlayerDevelopmentWatch()},/** * When build starts, build contentlayer. */asyncbuildStart(){awaitbuildContentlayer()},/** * TODO: When build ends, stop the contentlayer development watch. */asyncbuildEnd(){if(contentLayerWatcher!==undefined){contentLayerWatcher}},}}
Activity
stale commentedon Jun 7, 2022
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
nisarhassan12 commentedon Jul 5, 2023
Thanks to all the contributors for their great work on this project. I was wondering how many more votes is it gonna need before it gets worked on?
ghost-2e63 commentedon Jul 13, 2023
Sveltekit support will be much appreciated 馃槃 !!
seancdavis commentedon Jul 13, 2023
Tight integration with SvelteKit is not currently planned. However, you can still use Contentlayer with SvelteKit.
I've done this with other frameworks that aren't officially supported. It usually looks like this:
contentlayer devand the dev server in parallel.contentlayer buildprior to running the framework's build command.git-no commentedon Aug 6, 2023
I could create a working demo of a Sveltekit - Contentlayer - MDX integration with simple and little code.
For those interested here is the git repositiory: sveltekit-contentlayer-example
I hope this supports the Contentlayer project and helps to enlarge the Svelte / Contentlayer community.
Ahidada commentedon Aug 28, 2023
Can parse md, but SvelteKit doesn't have enough support for mdx
git-no commentedon Oct 22, 2023
@Ahidada
Quite an allegation. Maybe you can elaborate what support you are missing.
master-oppai commentedon Feb 18, 2024
yes please
ap0nia commentedon Mar 27, 2024
Given a repository that's prepared to import/render the contentlayer content, would a Vite plugin work? All it does is invoke
contentlayer buildandcontentlayer devduring the Vite lifecycle.janigowski commentedon Jun 26, 2026
Hey,
Would you mind to share some update on it?
Thanks
git-no commentedon Jun 27, 2026
@janigowski As you probably have read on the repo main page, this repo is no longer maintained; do not expect updates.
There are alternative solutions in the market, e.g. I switched to content-collections and it works successfully with SvelteKit.