I have a react component which has X options for a stylesheet to be imported which is using CSS Modules.
I ideally want to have a global environment variable fetched by using e.g.
process.env.THEME
I can't use:
import MyStyleSheet from `${process.env.THEME}/my.module.css`
I can use:
const MyStyleSheet = require(process.env.THEME/my.module.css);
however.....
import/no-dynamic-require
eslint rule kicks off saying its bad.
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
All the articles and posts I read say its not possible.
Surely this is a common want but I can't for the life of me work out how to do it. Any ideas?
Update:
import React from 'react';
const Classes = import('./${process.env.theme}/Button.module.css');
const Button = () => (
<button className={Classes.button}>My Themed Button</button>
);
export default Button;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…