Gregor Voinov
Gregor Voinov

Reputation: 2263

Use gsap with nuxtjs

I want to use gsap in combination with ScrollMagic. ScrollMagic is already implemented and it works fine, but when I want to use animation.gsap i get the error

These dependencies were not found: * TimelineMax in ./node_modules/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js * TweenMax in ./node_modules/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js

Therefore I installed gsap via npm

npm i gsap

and imported TimelineMax and TweenMax

if (process.browser) {
    const sm = require('ScrollMagic')

    require('gsap/TimelineMax')
    require('gsap/TweenMax')

    require('scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap')
    require('scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators')

    Vue.prototype.$sm = sm
    Vue.prototype.$smController = new sm.Controller()
}

and in my nuxt.config.js file i added gsap to the vendor array

vendor: ['gsap', 'ScrollMagic', 'vuebar', 'vee-validate'],

and in my component i use this code for a paralax-effect

new this.$sm.Scene({
    triggerElement: '#js-introduction-paralax',
    triggerHook: 'onEnter'
})
    .duration('200%')
    .setTween('#js-introduction-paralax', {
        backgroundPosition: '50% 100%'
        ease: Linear.easeNone
    })
    .addIndicators()
    .addTo(this.$smController)

but i still get the error that the dependecies were not found

UPDATE

I also tried to import it in this way

import { TweenMax, TimelineMax, Linear } from 'gsap'
or seperated
import TweenMax from 'gsap/TweenMax'; 
import TimelineMax from 'gsap/TimelineMax';

but same result

I also tried to make aliases

resolve: {
    modules:[
      path.resolve(__dirname), path.resolve(__dirname, "node_modules")
    ],
    alias: {
        "TweenMax": path.resolve('node_modules', 'gsap/TweenMax'),
        "TimelineMax": path.resolve('node_modules', 'gsap/TimelineMax'),
        "gsap": path.resolve('node_modules', 'gsap'),
    }
},

also same result

When i write in the console

window.TweenMax

I get this

ƒ (target, duration, vars) {
            TweenLite.call(this, target, duration, vars);
            this._cycle = 0;
            this._yoyo = (this.vars.yoyo === true || !!this.vars.yoyoEase);
            this._repeat = this.vars.repe…

so something is loaded...

Upvotes: 2

Views: 1836

Answers (1)

Vlad
Vlad

Reputation: 619

It maybe useful for you. I also have some errors like you, and I found a solution to my problem here.

import ScrollMagic from 'scrollmagic'
import {
    TweenMax,
    TimelineLite
} from 'gsap'

import 'imports-loader?define=>false!scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators'
import 'imports-loader?define=>false!scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap'

and don't forget to do

npm i scrollmagic imports-loader

Upvotes: 2

Related Questions