Good afternoon, I'm trying to split gulp.task into production and development. I do this through gulp-if, checking for a variable. But I plan to make it possible to set this variable through the console, and then run gulp.

I run the command: NODE_ENV=production gulp scss

Code that is not working. Gives an error message:

 ..\gulp-front-end>NODE_ENV "NODE_ENV" Π½Π΅ являСтся Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΉ ΠΈΠ»ΠΈ внСшнСй ΠΊΠΎΠΌΠ°Π½Π΄ΠΎΠΉ, исполняСмой ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΎΠΉ ΠΈΠ»ΠΈ ΠΏΠ°ΠΊΠ΅Ρ‚Π½Ρ‹ΠΌ Ρ„Π°ΠΉΠ»ΠΎΠΌ. 

Here is the code from gulp

 const gulpIf = require('gulp-if'); const isDevelopment = !process.env.NODE_ENV || process.env.NODE_ENV == 'development'; gulp.task('scss', function() { return gulp .src('source/scss/style.scss') .pipe(plumber( errorHandler )) .pipe(scss.sync()) .pipe(autoprefixer({ browsers: ['last 2 versions'], cascade: false })) .pipe(gulpIf(isDevelopment, cssnano())) .pipe(gulpIf(isDevelopment, rename({suffix: '.min'}))) .pipe(gulp.dest('build/css')); }); 

1 answer 1

In Windows, the set command is used to set environment variables. In your case, to run Gulp in a production environment, you should use this one-liner:

 set NODE_ENV="production" && gulp scss 
  • I will add a little: set NODE_ENV=production - set the variable, hit enter, then gulp scss will always collect the production version, to build the developer version you need to set the variable set NODE_ENV=development - pepel_xD
  • To keep in mind the current state of the variable NODE_ENV is a waste of energy. That is why I indicated in the response to using the && operation to set the environment variable and run the assembly. - Dmitriy Simushev
  • Well, all other launches will be made with this value until you change it again .... - pepel_xD
  • " Explicit is better than implicit. ";) - Dmitriy Simushev