alanmatkorski@gmail.com's avatar

.env variables in gulpfile.js

Is it possible to load .env variables with env() function within gulpfile.js?

0 likes
4 replies
itsjoshbruce's avatar

@martinbean

Might be nice to be able to change src paths based on environment without having to .gitignore the gulpfile.js and maintain different ones in all the environments.

// .env
APP_ENV=local
// gulpfile.js
if (env(APP_ENV) == 'local') {
    gulp.task('locals', function() {
        return gulp.src('../[some folder name]/**/*')
            .pipe(gulp.dest('[some local app path]'));
    });

} else if (env(APP_ENV) == 'prod') {
    gulp.task('locals', function() {
        return gulp.src('../../../[some folder name]/**/*')
            .pipe(gulp.dest('[some local app path]'));
    });
}

Server folder structure:

/site1
    /app
    /...
/site2
    /app
    /...
/site3
    /app
    /...
/universals-that-cannot-go-into-package-management
martinbean's avatar

@amidknight Not sure why you’ve dragged up a 7 month old conversation, but your build process should be the same across all environments.

Gulp is for building front-end assets (CSS, JavaScript), the paths of which shouldn’t change across environments.

Please or to participate in this conversation.