Jump to content

[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 = {};

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. 

Share this post

Link to post
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;




Share this post

Link to post
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:

var gs = window.GreenSockGlobals = {};
var gs = this.GreenSockGlobals = {};
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)? 

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.