javascript - What is the point of envifying client side libraries? -


in attempt address problem behind warning coming redux stumbled across the advice explains envifying necessary step when using react or redux in order produce build optimized production use. envifying explained process of substituting node specific environment variables such process.env.node_env actual values such 'production'.

accepting envifying necessary , above explanation true, confuses me since seems assume client side libraries such react , redux contain node specific environment variables. yeah know these libraries in particular popular building isomorphic/universal javascript applications find surprising. i'm understanding correctly? if there explanation of pattern need aware of process.env.node_env used outside of node?

if understand advice suggest if i'm using webpack may want use plugin such defineplugin so.

  new webpack.defineplugin({     "process.env.node_env": process.env.node_env,   }), 

which appear require set node_env variable target environment of build want produce client side code. doubly strange because i'm setting environment variable on build server reflect environment should actual code run on server deployed to.

all makes me feel i'm missing in terms of general pattern.

related information:

you can have production , development builds / conditions web apps too! mentioned, many isomorphic js frameworks make use of it.

envify serves out in 2 primary ways code uses process.env

  1. remove need shims support it- browserify has automated 1 clocking in @ ~2kb, , can matter.
  2. minify code better- when code becomes if ("development" === "production") minifier can strip out completely

remember webpack transforming (in general, client-side) code. adding find-replace instances of process.env within use case, , lets create environment-based behaviors without introducing new api. setting value in webpack.config no different setting environment variable on operating system.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -