Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing global variable between files possible? #3

Closed
xmlking opened this issue Jul 5, 2014 · 3 comments
Closed

Sharing global variable between files possible? #3

xmlking opened this issue Jul 5, 2014 · 3 comments

Comments

@xmlking
Copy link

xmlking commented Jul 5, 2014

I have a main file gulpfile.js with variable env initialized.

var gulp = require('gulp');
require('require-dir')('./gulp');

var env = process.env.NODE_ENV  || 'DEV';

gulp.task('default', ['clean'], function () {
    gulp.start('build');
});

I want to use env in ./gulp/build.js

gulp.task('styles', function () {
    return gulp.src('app/styles/main.scss')
        .pipe($.plumber())
        .pipe($.rubySass({
            style: 'expanded',
            precision: 10,
            sourcemap: (env === 'DEV')
        }))
        .pipe($.autoprefixer('last 2 version'))
        .pipe(gulp.dest('.tmp/styles'));
});

may be in some other child file , i want to override env global variable. is it possible ?

@aseemk
Copy link
Owner

aseemk commented Aug 3, 2014

Sorry for the delay here @xmlking!

Unfortunately, no, it's not possible to share a variable across files. This is a limitation (by design) of Node. Your only option would be to move that variable to a shared file/module.

Hope that helps!

@aseemk aseemk closed this as completed Aug 3, 2014
@NeXTs
Copy link

NeXTs commented Dec 8, 2015

global.env = process.env.NODE_ENV  || 'DEV';

in other module

console.log(env);

@xmlking
Copy link
Author

xmlking commented Dec 8, 2015

This works but, order of code execution is not garented.
See : node-config/node-config#246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants