-
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
Better npm/browserify support #254
Conversation
e4680f0
to
db014fc
Compare
It's not perfect but it's better, and plugins are now usable. Example of use:
To make loading plugins nicer, they could be wrapped in the root directory somehow, or better yet, published in their own npm package. |
you probably mean |
Sorry, I wasn't talking about dedupe, that's actually not a problem since scrollmagic doesn't have a strict dependency on gsap (nor should it, since only an optional plugin depends on it). I meant I would like to do this:
instead of
Note, nr 1 can be done with some prepublish script which flattens the package before it's sent to npm, or even simpler by having a dummy commonjs file named Nr 2 can be done by splitting the plugins into their own repos and npm packages. If preferred, it would also be possible to publish multiple npm packages from this repo using some tricks. |
Hi there and thanks for your help and input. I was actually thinking about doing something like this as well, but wasn't sure how to work with the dependencies in the plugins. (I also don't work with browserify) Have you tested this? I definitely prefer solution Nr1, because I want to keep all plugins organized in the same package. I would also like to ask you to change the pull request to only contain the files in the dev folder. thanks again and best regards, |
db014fc
to
4b28b00
Compare
There isn't really a hard dependency on gsap, the developer needs to install it manually for the gsap plugin to work. I can understand having the plugins in the same package, but that actually doesn't follow the spirit of npm. Separating them in npm would allow the gsap plugin to have an explicit dependency on gsap. You could still keep the code for all of the packages in this repo, and distribute them together for bower or downloading. Anyway, I do respect your opinion and this is good enough for now. So this PR works for me. I am currently using ScrollMagic in a Browserify-based project, with gsap and debug plugins, exactly like the first code example. I have not used or seen any client-side npm packages which are published with minified code. You need Browserify anyways which handles the concatenation, and minification is very easy from there. It is quite addicting to have an unminified source map of all project and library code in the browser. Sorry about the dist files, that makes sense. I've rebased this PR to not include dist files. PTAL |
Fix plugin dependencies. Exporting ScrollMagic directly. Support gsap’s strange exports.
4b28b00
to
4263e30
Compare
I hear ya, but ScrollMagic wasn't originally intended as an npm package. It is for my lack of knowledge here that I am unsure if I should kick the minified source from the npm package. The reason is even if it is true, that people who use npm always do their own minification (through browserify or other) they will miss several optimizations that the minified files from the dist have. Lines 209 to 224 in 5c7fae2
So what's the opinion here? |
Better npm/browserify support
That's actually a very good point, about the optimizations. I haven't actually noticed how other client-side libraries deal with code changes between dev and prod versions. I think few people care and some don't mind dead debug code in their bundles (assuming it can be turned off at runtime). Maybe predefines and dead code removal in UglifyJS can handle this in a more standard way. Then those that care, can configure it manually. I do realise that's not optimal.
|
Well this solution would still mean that all the debug text information (which are strings) would be exported to the minified file, making it unnecessarily big. Long story short I think the best way to go is flattening the file structure, as suggested and leave both the regular and minified files in there. It should be the same as it currently is on cdnjs, where This should be done using a postinstall script. Do you agree? Another question that remains is how to treat the |
I'm with you. Tough, I think there must be a better solution for the future. At the moment of reading I thought that "plugin" is probably not the best word describing what is in this folder. Since the actual plugins are loaded via //cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js et al, these files behave more like "adapters" for the plugins. Or am I missing sth? |
Mh. They are indeed more like "extensions". |
Hm, I'm not sure if you understood. Using my example, uglify would remove the whole if clause since it's dead code, so nothing inside it would show up in minified code. For flattening, another option is to build the whole npm package structure into a subfolder with gulp, including a correct package json file, and publish from there. NPM recommends using prepublish scripts instead of postinstall scripts to keep the package tar ready to consume with minimal cruft and dependencies (don't want to test the postinstall script on all target OS's). |
Ah, I see now. I didn't know uglify did that. Regarding publishing this is also a very good Idea. What do you think? |
I don't think this is a commonly used feature in browserify. Nor do I think it's commonly used to fix this problem of supporting both dev/dist code in npm, it's not very intuitive for users as you say. But I do think it's a smart way to skip code in production, and useful to both libraries and size-sensitive websites.
The publishing plan sounds really good to me. |
So here's what I decided: Publishing logic: Lines 308 to 326 in fcc3255
One is executed pre-publish and one post-publish. The prepublish one copies the dist files to the root folder and modifies the package.json accordingly. The postpublish one basically reverts to the original state. I can't test it now, because the version number would need to be bumped for that, but we'll see if it works, when that happens. Any input? |
I like it. Especially that the old require paths will still work. I think there is just one more issue, and that's how the plugins find ScrollMagic. They're now doing But I think we want to make sure that:
I'll think some more if there is a simple way to achieve this. |
actually they won't. Regarding your 1) and 2) I can't really make an informed decision, because I lack knowledge here. |
Any chance we can open this back up? None of the suggestions are working, and not running this through browserify or webpack in 2015 is insane. |
^^^^^^ |
+1 |
1 similar comment
+1 |
I wonder if there's any changes made on this. Still can't make it working with browserify |
Unfortunately it still does not work as expected.... |
asking again in 2018 |
Fix plugin dependencies.
Export ScrollMagic directly.
Support gsap’s strange exports.