I'm currently following the native next.js style approach using css modules. Within my project, I have multiple global css variables defined in theme files that need to be added to the app. Here is an example of what one of these theme files looks like:
// theme.css
:root {
--PRIMARY_COLOR: #504f94;
--PRIMARY_BRIGHT_COLOR: #926ba7;
--PRIMARY_COLOR_ACCENT: #3e3d81;
--SECONDARY_COLOR: #102f31;
--SECONDARY_COLOR_ACCENT: #1d2020;
}
The challenge I am facing is that I have several of these theme files in my project and I need to select and use only one based on an environment variable. This decision needs to be made server-side.
My question is, how can I dynamically insert styles into custom _document.js or _app.js after deciding which theme to use? Additionally, I want to ensure that only the selected theme's code gets included in the bundle and not others.