1

I'd like to have multiple builds of application where each build would represent specified theme.

npm build monokai would generate monokai theme. Project structure would be like this:

/themes/default/component.jsx
/themes/monokai/component.jsx

Basically it would come down to this /themes/{themeName}/component.jsx. Of course there would be whole folder structure in {themeName} subdirectory, but every theme would have same folder structure, just different html/css.

Is there a way to achieve this with webpack? It doesn't necessarily have to work via npm build {themeName}.

zhuber
  • 5,364
  • 3
  • 30
  • 63
  • so inject the theme as a global. then dynamically import based off of that theme – John Ruddell Jun 04 '18 at 07:59
  • @JohnRuddell I don't think I understand, can you explain in a bit more detail? – zhuber Jun 04 '18 at 08:00
  • so, you can access variables via `process.env.npm_config_` if you take that variable (aka your theme) and use it to import the theme you should be set. [See this for an example of injecting](https://stackoverflow.com/a/19381235/2733506). if you are still having issues put up a codepen or something and ill try and help you with your chunk of code :) – John Ruddell Jun 04 '18 at 08:05
  • @JohnRuddell but that would mean that I should import every file via process.env.npm_config_? Because that is what I want to avoid and just import { Login } from 'themes/login' which would resolve to 'themes/default/login' – zhuber Jun 04 '18 at 08:14
  • 1
    no, lol you should use the theme defined in a build to set a variable in your application. a theme variable. Then you would import based off that theme – John Ruddell Jun 04 '18 at 08:16
  • This is too complicated to just give an answer, if you have a github repo or some place where code is i can help you with it.. but its pretty complicated to just do dynamic importing based off some variable like that – John Ruddell Jun 04 '18 at 08:17

0 Answers0