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

Generate parsed content during module boot in production #1387

Closed
Atinux opened this issue Jul 27, 2022 — with Volta.net · 8 comments · Fixed by #1411
Closed

Generate parsed content during module boot in production #1387

Atinux opened this issue Jul 27, 2022 — with Volta.net · 8 comments · Fixed by #1411
Assignees
Labels
enhancement New feature or request

Comments

Copy link
Member

Atinux commented Jul 27, 2022

Instead of adding the /api/_content/cache route in pre-render.

This way, Tailwind JIT (and others) will work.

@Atinux Atinux added the enhancement New feature or request label Jul 27, 2022 — with Volta.net
@farnabaz
Copy link
Member

AFAIK there is two way to achieve this goal:

  1. Create a secondary build of Nuxt, generate parsed contents by calling nitro APIs, and move the caches to the main build.
  • I am not sure how we can do this, I tried to create a secondary build inside the module but couldn't make it. From my understanding Nuxt can only have one live context at the time and calling kit.loadNuxt inside the module will fail. Maybe @danielroe and @pi0 could help us on this
  1. Simulate parsing inside the module, resolve transformers, remark/rehype plugins ... and parse and store contents in the cache directory.
  • This way content hooks will not work (beforeParse, afterParse) and the generated parsed content will be wrong in these cases. (Nuxt Windicss uses these hooks)

WDYT @Atinux @pi0

Copy link
Member Author

Atinux commented Jul 29, 2022

Can we at least, load all the raw files from the sources and store them? This way we can link to this directory for both dev and production, this is fine and faster as boot time and solve the CSS parsing issue for production for TailwindCSS

@pi0
Copy link
Member

pi0 commented Aug 1, 2022

Can you please explain more specifically what information from raw sources is needed? I think in order for tailwind styles to be discovered, we need raw content sources (accessible from the build-context storage instance) and a simpler parser that can parse/extract a list of components and used classes from markdown files to be provided to jits such as tailwind..

Copy link
Member Author

Atinux commented Aug 1, 2022

Basically we need the content from sources for TailwindCSS to analyse: https://github.com/nuxt/content/blob/main/src/module.ts#L548

The issue here is that the parsed content is available after the nuxi build

@pi0
Copy link
Member

pi0 commented Aug 1, 2022

I see but I think unparsed markdowns pulled from storage sources should be also enough for a tailwind to match class usages right?

@farnabaz
Copy link
Member

farnabaz commented Aug 1, 2022

I think tailwind has some issues with extracting classes from raw markdown files.

/cc @Tahul

Copy link
Member Author

Atinux commented Aug 1, 2022

Not it is working in dev, it's only because we don't have the content in production that is fails.

@farnabaz
Copy link
Member

farnabaz commented Aug 3, 2022

As I checked tailwind build happens before nitro create/init, therefore we can't use nitro.storage to fetch remote contents.

The solution is to create a storage instance in before:build hook, mount drivers, and fetch all contents and store them in cache dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants