Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Ciberman

[node.js] using GSAP WITHOUT polluting the global scope.

Recommended Posts

Hello. I am trying to use GSAP with node.js WITHOUT polluting the global scope. 
I am ussing nw.js (so, I have available the window object)

 

First I do:

npm install gsap --save

Then in my Tween.js:

var gs = window.GreenSockGlobals = {};
require('gsap');

console.log(gs); // logs empty object
console.log(window.GreenSockGlobals); // logs empty object
console.log(window); // logs the window object, with ALL the GSAP stuff in it
console.log(window.TweenLite); // logs tweenlite object

I don't want to have all the GSAP stuff in the global scope. I want to have it in a specified object. 
Thanks. 

Link to comment
Share on other sites

I have done it. I have commented inside TweenMax.js the line:

module.exports = _exports[moduleName] = cl;

and replaced by:

module.exports = _exports;

Image: 

 

EeoUaMT.png

Link to comment
Share on other sites

Glad you got it working. 
 

I'm not an expert with node, but I wonder if it would have helped if you referred to "this" instead of "window", like:

//OLD
var gs = window.GreenSockGlobals = {};
//NEW
var gs = this.GreenSockGlobals = {};
//OR MAYBE:
var gs = global.GreenSockGlobals = {};

(that must be run before the GSAP files are loaded). 

 

Anyway, thanks for reporting back with what you changed. I'm also kinda curious about why it's important to you to avoid having GSAP values added to the global scope. Are you under the impression that there's a big performance issue (there's not)? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×