Using greensock with browserify

对着背影说爱祢 提交于 2019-12-12 14:07:11

问题


I'm not able to get TweeLite to work with browserify. I'm an extreme noob when it comes to CommonJS.

I've installed gasp v1.13.2 using Bower and include it like this:

var TweenLite = require("../../bower_components/gsap/src/minified/TweenLite.min.js");

I don't get any errors when using it, but my animations don't work. According to gsap docs this version should work without a shim. What am I doing wrong? Can anyone provide a working example?

https://greensock.com/gsap-1-13-1

I've just started on a project so I dont have any interesting code to show. I'm using the gulp-starter boilerplate.


回答1:


Try using the uncompressed GSAP libraries. I'm successfully using them through browserify and installed with bower. Like this:

var TweenLite = require('../bower_components/gsap/src/uncompressed/TweenLite.js');
var TimelineLite = require('../bower_components/gsap/src/uncompressed/TimelineLite.js');
var CSSPlugin = require('../bower_components/gsap/src/uncompressed/plugins/CSSPlugin.js');

However, if I switch to the compressed builds browserify no longer finds the modules.

It appear like the compression methods used to generate the minified builds somehow broke the module exports.




回答2:


GSAP is also available through NPM so you should be able to install it via:

npm install gsap --save

and use it the same way other libraries are referenced in the gulp-starter project eg in view.coffee:

_          = require 'underscore'
Backbone   = require 'backbone'
Backbone.$ = require 'jquery'
plugin     = require 'plugin'
//this line below makes TweenLite available in the browser in my quick tests.
gsap       = require 'gsap'


来源:https://stackoverflow.com/questions/26325273/using-greensock-with-browserify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!