Agu V Agu V - 7 months ago 91
Javascript Question

How can i add velocity plugin to ScrollMagic with npm?

I need to add scrollMagic with velocity plugin to my npm library.

package.json

{
"name": "library",
"version": "1.0.10",
"description": "blabla",
"main": "index.js",
"dependencies": {
"shortid": "2.x",
"jquery": "2.x",
"scrollmagic": "2.x"
}
}


Is there a way to do that?

Simply adding ScrollMagic does not include plugins.

Please let me know if more info is needed.

EDIT:

If i add the plugin like this: require('scrollmagic/uncompressed/plugins/animation.velocity.js')

I get these error.

ERROR in ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.velocity.js
Module not found: Error: Cannot resolve module 'ScrollMagic' in /home/av/local.dev/testest/node_modules/scrollmagic/scrollmagic/uncompressed/plugins
@ ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.velocity.js 31:2-46

ERROR in ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.velocity.js
Module not found: Error: Cannot resolve module 'velocity' in /home/av/local.dev/testest/node_modules/scrollmagic/scrollmagic/uncompressed/plugins
@ ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.velocity.js 31:2-46

Answer

i've added these libraries to resove in webpack.config.js:

resolve: {
        extensions: ['', '.js', '.json'],
        root: [Path.join(__dirname, "node_modules")],
        modulesDirectories: ['node_modules'],
        alias: {
            "ScrollMagic": Path.resolve('node_modules', 'scrollmagic/scrollmagic/minified/ScrollMagic.min.js'),
            "animation.velocity": Path.resolve('node_modules', 'scrollmagic/scrollmagic/minified/plugins/animation.velocity.min.js'),
            "velocity": Path.resolve('node_modules', 'velocity-animate/velocity.min.js')
        }
    }