saltyshiomix / react-ssr

React SSR as a view template engine
https://npm.im/@react-ssr/express
MIT License
267 stars 44 forks source link

NODE_ENV customization #24

Closed Krakof closed 4 years ago

Krakof commented 4 years ago

Hi, For some reason I have NODE_ENV="k8s" for kubernetes, so in this case ssr part builds in dev mode when the whole app works in production. To fix this I have to customize npm script with: start: "NODE_ENV=production ts-node ....." But what if I need my origin NODE_ENV and can't change it. Could you please add some customization to be able to control build mode(e.g second parameter at register function):

register.ts

if (process.env.NODE_ENV === 'production') {
    await (await import('./optimize/production')).default(app);
  } else {
    await (await import('./optimize/development')).default(app);
  }

webpack.config.js and may be in other files

Thanks in advance

saltyshiomix commented 4 years ago

@Krakof

Ok, I'll add ssr.config.js#webpackMode 👍

I hope this will help for you :)

Krakof commented 4 years ago

@saltyshiomix Sorry for annoying you. It would be great to run whole ssr in specific mode not only webpack.

if (process.env.NODE_ENV === 'production') {
    await (await import('./optimize/production')).default(app);
  } else {
    await (await import('./optimize/development')).default(app);
  }

may be we can pass node_env as second parameter to register function? Thanks

saltyshiomix commented 4 years ago

@Krakof Ok, I got it! I'll try it soon :)

saltyshiomix commented 4 years ago

@Krakof

You want to run the app with process.env.NODE_ENV === 'k8s' and want to choice react-ssr's ENV (development or production), right?

saltyshiomix commented 4 years ago

@Krakof

Another choice, Do you like process.env.REACT_SSR_ENV?

saltyshiomix commented 4 years ago

@Krakof

I added process.env.REACT_SSR_ENV for now.

Could you try @react-ssr/nestjs-express@^0.21.15?

package.json

{
  "scripts": {
    "start": "cross-env NODE_ENV=k8s REACT_SSR_ENV=production node dist/main.js"
  }
}
Krakof commented 4 years ago

Everything works, thanks a lot.