Skip to content

Conversation

@davesnx
Copy link
Owner

@davesnx davesnx commented Sep 2, 2025

Implements CSS extraction discussed here #433

styled-ppx is now able to generate static CSS files. It runs on top of dune rules, and the invokation is styled-ppx.generate

(rule
 (target styles.css) ; The file it will generate
 (deps
  (glob_files_rec %{project_root}/**.pp.ml)) ; The files you want to capture styles from 
 (action
  (run styled-ppx.generate --output %{target} %{deps}))) ; The action needed

Note: For ReScript users, we should use generators or call the invokation on the build system or make styled-ppx itself generate the files. I dunno about the design yet, but I'm a bit worried since there are a few problems for ReScript #415, for now I will prio Melange/native since I can battle-test it.

Fixes #516

Since we use glob_files_rec <glob> we solved the "one shot" stylesheets from native #516.

Users can run the styled-ppx.generate action at any location they choose, watching any part of the codebase they prefer and eliminating the problem of including all styles into one big Stylesheet for native.

Improves error messages by a lot and fixes some locations #429

image image

Starts with the first stone of unifying both lexers #432

A bit of an unrelated, but merged into this branch #561

We will use a single lexer for parsing both the stylesheet and the properties, and also type-check properties. Future work will be to join both libraries and remove a bit of glue code.

davesnx added 11 commits August 28, 2025 18:20
…messages

Previously, type errors in generated code would show '_none_, line 1' which
provided no useful debugging information. This commit ensures that all generated
AST nodes have proper location information that traces back to the original
source location.

Changes:
- Fixed location propagation in CSS module identifier generation
- Improved render_variable to preserve location information
- Enhanced addLabel to include location in all generated expressions
- Ensured render_make_call maintains proper location attributes

Now type errors show actual file names and line numbers (e.g., 'test_styles.ml, lines 78-88')
instead of unhelpful '_none_' locations.
@vercel
Copy link

vercel bot commented Sep 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
styled-ppx Ignored Ignored Preview Oct 20, 2025 9:50am

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@github-actions
Copy link

github-actions bot commented Sep 2, 2025

New nightly version has been published to the NPM registry: @davesnx/[email protected].
Install it with npm install @davesnx/styled-ppx@nightly or npm install @davesnx/[email protected].

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server-side apis get all stylesheet at once (maybe it should only get the "current")

1 participant