-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPM issue #324
Comments
I can do require("../node_modules/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js"); But then grunt gives me the error:
|
I managed to resolve require with webpack aliases var webpack = require("webpack");
var path = require('path');
module.exports = {
output: {
filename: "scripts.min.js"
},
resolve: {
root: [path.join(__dirname, "node_modules")],
extensions: ['', '.js', '.coffee', '.html'],
modulesDirectories: ['node_modules'],
alias: {
"npm": 'node_modules',
"TweenLite": __dirname + '/node_modules/gsap/src/uncompressed/TweenLite.js',
"TweenMax": __dirname + '/node_modules/gsap/src/uncompressed/TweenMax.js',
"TimelineLite": __dirname + '/node_modules/gsap/src/uncompressed/TimelineLite.js',
"TimelineMax": __dirname + '/node_modules/gsap/src/uncompressed/TimelineMax.js',
"scrollmagic": __dirname + '/node_modules/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js',
"animation.gsap": __dirname + '/node_modules/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js',
"debug.addIndicators": __dirname + '/node_modules/scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js'
}
},
module: {
loaders: [
{ test: /\.coffee$/, loader: 'coffee' }
]
},
plugins: [
//new webpack.ResolverPlugin(
// new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
//),
//new webpack.optimize.DedupePlugin(),
//new webpack.optimize.AggressiveMergingPlugin(),
new webpack.ProvidePlugin({
jQuery: "jquery",
$: "jquery",
jquery: "jquery"
})
]
}; But i am still getting this error:
|
I managed to do it with script-loader. Once installed i can call my scripts with: require("script!ScrollToPlugin");
require("script!scrollmagic");
require("script!animation.gsap");
require("script!debug.addIndicators"); This executes the file in a global context. |
Hey there. var $ = require("jquery");
var ScrollMagic = require("scrollmagic");
require('scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap');
var gsap = require("gsap"); I can see that this isn't very intuitive and this was discussed here: #254 In future versions you might be able to include the plugin like this: require('scrollmagic/plugins/animation.gsap'); |
OK, thanks. |
So, what is the preferred method to use ScrollMagic with Browserify? Directly linking to the plugins doesn't seem to work (anymore). |
This worked for me on Webpack: resolve: {
alias: {
"TweenLite": Path.resolve('node_modules', 'gsap/src/uncompressed/TweenLite.js'),
"TweenMax": Path.resolve('node_modules', 'gsap/src/uncompressed/TweenMax.js'),
"TimelineLite": Path.resolve('node_modules', 'gsap/src/uncompressed/TimelineLite.js'),
"TimelineMax": Path.resolve('node_modules', 'gsap/src/uncompressed/TimelineMax.js'),
"ScrollMagic": Path.resolve('node_modules', 'scrollmagic/scrollmagic/uncompressed/ScrollMagic.js'),
"animation.gsap": Path.resolve('node_modules', 'scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js'),
"debug.addIndicators": Path.resolve('node_modules', 'scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js')
}
}, Somewhere in your code: const ScrollMagic = require('ScrollMagic');
require('animation.gsap');
require('debug.addIndicators');
const TimelineMax = require('TimelineMax'); I needed the exact same spelling |
Also you probably should load gsap before scrollmagic, since scrollmagic depends on it. |
Thanks @steffenmllr, can confirm this works for me in Webpack |
The solution above in the post from @steffenmllr works great, when I had this broken I was half there, I did not fully qualify the path for TweenLite/Max TimelineLite/Max but did qualify the ScrollMagic packages. Make sure one sets up an alias for all of them and imports them using the exactly named alias. |
in @steffenmllr you may run into issues unless you |
For Webpack4 the below got it all working for me. The below uses resolve.modules ///webpack.config.js
resolve: {
modules: ['node_modules'],
alias: {
'TweenLite': 'gsap/src/minified/TweenLite.min.js',
'TweenMax': 'gsap/src/minified/TweenMax.min.js',
'TimelineLite': 'gsap/src/minified/TimelineLite.min.js',
'TimelineMax': 'gsap/src/minified/TimelineMax.min.js',
'ScrollMagic': 'scrollmagic/scrollmagic/minified/ScrollMagic.min.js',
'animation.gsap': 'scrollmagic/scrollmagic/minified/plugins/animation.gsap.min.js',
'debug.addIndicators': 'scrollmagic/scrollmagic/minified/plugins/debug.addIndicators.min.js'
}
} Import TweenMax prior to ScrollMagic // app.js
import TweenMax from 'TweenMax';
import ScrollMagic from 'ScrollMagic';
import 'animation.gsap';
import 'debug.addIndicators'; |
@denisinla Thanks! That worked for me. |
@denisinla you saved my day, dude.... That worked for me. |
This PR would be the solution #684 |
Hi Jan,
My question is not directly related to ScrollMagic. My code has grown and i decided to use npm, gulp, webpack for frontend.
On top of my file i have:
I am getting following errors in my console:
How can i require a plugin?
The text was updated successfully, but these errors were encountered: