Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path #464

Open
firxworx opened this issue May 26, 2023 · 4 comments
Milestone

Comments

@firxworx
Copy link

I tried getting Contentlayer rolling in an nx monorepo and found the developer experience to be poor.

I'm creating an issue to potentially influence the roadmap per the project website.
Contentlayer seems like a decent approach to supporting mdx that covers many use-cases so it'd be great to use it.

If you want to make this issue about one thing: developers should be able to configure the .contentlayer output location such that multiple sites/apps can be cleanly supported.

Context

In a monorepo a developer may have a nextjs blog/website/app at apps/my-app-name or packages/my-app-name.
(or even in an even deeper nested path in really large projects)

A given monorepo may house many different apps and libraries.

Developer Requirements

Contentlayer should not "take over" a project's root folder unless configured to do so, and it should support a monorepo where there may be several apps that use it and others that do not. An organization might have respective blog, product documentation, and marketing websites, each with their own MDX content; an individual might have multiple blogs.

  • a way to specify the path to the .contentlayer output dir for a given website/app that uses it
  • a straightforward and documented way to specify where the contentlayer config file is
  • contentlayer to consider where tsconfig.json is based on the path to its config (and/or specify a custom path to tsconfig)
    • right now contentlayer looks in the root of the project folder vs. where the config file is
    • nx apps have a tsconfig.json in their respective folders (it extends tsconfig.base.json in monorepo root)

Its ok if that's the default behaviour / happy path is no monorepo however I think there should be ways to support them far more elegantly.

In many cases would be best to be best to house everything together in each app's respective folder: the website content mdx, the contentlayer output, and the app itself.

In other cases a dev might prefer paths for content at the root of the project folder e.g. .contentlayer/ with subfolders for each app, content/ with subfolders for each app's content, etc off the project root.

Acceptance

Consider the scenario where a dev runs pnpm nx serve my-nextjs-app that's housed in apps/my-nextjs-app and everything is clean, organized, and plays nice and the console output isn't filled with confused contentlayer barf.

Documentation Issues

It is not well-documented that I can use createContentlayerPlugin() in next config to specify a configPath.

The docs at https://www.contentlayer.dev/docs/reference/next-contentlayer don't mention any of the "non default configuration options" but mention the existence. I had to find that out from looking at issue comments and PR's e.g. #248

@schickling schickling added this to the Pre-1.0 milestone May 26, 2023
@schickling
Copy link
Collaborator

Thanks a lot for this detailed and helpful write up. I'll try to keep the requirements from above in mind when working on the respective parts of Contentlayer going forward. Given some of the requirements you've listed above are also useful "standalone" feature requests, I'd encourage you to open individual issues for the self-contained feature requests and link them in your issue above which will make it easier to track the progress on this issue.

It would also be great to provide some notes on current workarounds - if there are any.

@airtonix
Copy link

Not sure how it's working now, but obviously ideal scenario would be contentlayer uses some way to get a resolved tsconfig object from reading the nearest tsconfig file.
Currently it feels like it's just const tsconfigjson = require('.tsconfig.json') the file raw.

If it is this way due to technical debit that can't be paid now, then a alternative solution for now would be to allow the cli tool and the nextjs-config to accept a parameter that controls what tsconfig file it uses.

This way, I can regenerate that file for contentlayer by merging the root and the current nextjs tsconfig.

@samyosm
Copy link

samyosm commented Oct 7, 2023

Has anyone found a workaround for this yet?

@samyosm
Copy link

samyosm commented Oct 7, 2023

Here's what I found:

// apps/[your-app]/next.config.js
const withContentlayer = createContentlayerPlugin({
  configPath: './apps/[your-app]/contentlayer.config.ts',
});

module.exports = withContentlayer(...);
// apps/[your-app]/contentlayer.config.ts

/* ... */

export default makeSource({
  /* ... */
  contentDirPath: './apps/[your-app]/[post]',
  /* ... */
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants