How to set React to production mode when using Gulp

后端 未结 5 1811
盖世英雄少女心
盖世英雄少女心 2021-02-03 20:36

I need to run React in production mode, which presumably entails defining the following somewhere in the enviornment:

process.env.NODE_ENV = \'production\';
         


        
5条回答
  •  醉梦人生
    2021-02-03 21:04

    To set React in production mode you need to set your NODE_ENV variable to production and uglify your JS as an extra step.

    You're already taking care of the uglification, for setting your NODE_ENV variable :

    • Set the variable while running the gulp task :

    NODE_ENV='production' gulp

    • OR set it from inside your gulpfile by doing something like this :

    gulp.task('set-production-env', function() { return process.env.NODE_ENV = 'production'; });

提交回复
热议问题