0

I'm trying to optimize my website. I would like to create the thinnest build possible.

I have a .env file containing

REACT_APP_ENV = DEV

Here is an exemple of what I want to reduce :

if (REACT_APP_ENV === "DEV) {
   // DO SOMETHING A
} else {
   // DO SOMETHING B
}

I would like to reduce it to :

// DO SOMETHING A

Is there a way to create a reduced build like this ?

We already know that REACT_APP_ENV === DEV when building, so it seems possible to me that we can simplify this code.

Currently, I am using webpack with babel to build.

If you have any clues, I'd appreciate to see them.

Thank you for reading

Randyop
  • 1
  • 1
  • Are you using a transpiler? I'm certain there are plugins that do this. – Bergi Dec 02 '20 at 14:01
  • https://create-react-app.dev/docs/adding-custom-environment-variables/. Also, take a look at https://reactjs.org/docs/code-splitting.html#reactlazy – Punit Makwana Dec 02 '20 at 14:05
  • @Bergi I use webpack and babel, I haven't find any plugins yet – Randyop Dec 02 '20 at 14:20
  • @PunitMakwana Even if I use lazy imports, the weight of the build doesn't change. The code is not reduced like in my example above – Randyop Dec 02 '20 at 14:21
  • Have a look at https://stackoverflow.com/q/33117227/1048572, https://stackoverflow.com/q/30030031/1048572 and https://blog.bigbinary.com/2015/08/26/code-optimize-javascript-code-using-babeljs.html (which employs the [minify constant folding](https://babeljs.io/docs/en/babel-plugin-minify-constant-folding) and [minify dead code elimination](https://babeljs.io/docs/en/babel-plugin-minify-dead-code-elimination) plugins) – Bergi Dec 02 '20 at 15:07
  • It didn't reduce the size, but thanks for your help, your links helped me to understand better how it works ! – Randyop Dec 14 '20 at 10:24

0 Answers0