Next.js Discord

Discord Forum

Where to put JS/CSS tree-shaking plugin

Unanswered
Spinone Italiano posted this in #help-forum
Open in Discord
Spinone ItalianoOP
I have large JSON files that specify a "theme" with colors and spacing values. I translate these into CSS vars.
I don't want these to be bundled with my app, since there are a lot of them.
Instead, I would like to find usages of the CSS variables (var(--my-var)) and analogous JS functions that pulls the CSS variables (getCSSVar), and only bundle the CSS variables used by my app.

Given Next's SWC compilation architecture, I'm trying to figure out where to put this. I could have it as a separate npm run build:theme function, but it'd be nice to have it built into the normal next dev or next build commands so it can live-reload.

Any help appreciated!

0 Replies