lxs24sxl / vite-plugin-html-env

A vite plugin for rewriting html
82 stars 10 forks source link

how to use if conditional #9

Closed paper-florent closed 2 years ago

paper-florent commented 2 years ago

Hello first thank you for your work !

Have a question. How do you actually add a condition rendering ?

<{ if(MODE !== 'development'){  }>

Do you know how I can achieve that ?

Thank you a lot

lxs24sxl commented 2 years ago

In general, environment variables are fixed values, so you can create different .env files to distinguish between environments.

.env (loaded in all cases)

VITE_APP_PRODUCTION_SOURCE_MAP=1

.env.development (only loaded in specified mode)

VITE_APP_PRODUCTION_SOURCE_MAP=0
paper-florent commented 2 years ago

I did a bit differently by adding a plugin. I wanted to load a script in the html base on the env. But with a plugins its working kind of the same