I have a project that uses Linaria and I want to set the theme at build time using an environment variable. The Theme.js file goes something like this:
const theme = process.env.REACT_APP_THEME_NAME === 'MAIN'
? require('../theme-variables.js')
: require('../theme-variables-alt.js')
export { theme };
and there is a Button.js file that goes like this
import { styled } from 'linaria/react';
import { theme } from '../Theme';
const Button = styled('button')`
background-color: ${theme.colors.blue};
`;
However, for some reason during interpolation, the complied CSS will only contain the values from the alt file despite the REACT_APP_THEME_NAME environment variable being set to MAIN.
https://codesandbox.io/s/linaria-demo-forked-q25fw?file=/src/App.js
Additionally, it was suggested in discord that in the process.ts file if we were to pass all the environment variables through and not just the NODE_ENV, this would be solved however I experimented by modifying it like so:
export const env = {
NODE_ENV: process.env.NODE_ENV,
REACT_APP_THEME_NAME: process.env.REACT_APP_THEME_NAME
}
and the problem persists
Hi @woahitsraj
Can you please confirm, that the problem has gone?
Hi @Anber, thanks for looking into this. I'm not able to verify because the linaria/react module is now missing. Should I raise a new issue?
Have you checked in rc.3?
Yes this is in 2.0.0-rc.3 Additionally, my minimal example is failing because of a missing module gensync. https://codesandbox.io/s/linaria-demo-forked-q25fw?file=/src/App.js
Ok, thank you. I'll check it ASAP
Hi @woahitsraj!
There are actually a few different problems:
styled.h1 and not just styled).Here is a working sandbox https://codesandbox.io/s/linaria-demo-forked-y0vwn?file=/package.json
Amazing! Thank you so much