jedwards1211 / meteor-imports-webpack-plugin

Webpack plugin to import and use Meteor packages like if they were real NPM packages.
MIT License
25 stars 10 forks source link

make plugin work with webpack 2 #9

Closed jedwards1211 closed 8 years ago

jedwards1211 commented 8 years ago

I really have no idea if I'm doing it correctly, but it works :P There's not much official documentation of how to write plugins for Webpack 2 yet so I just figured this out by trial and error, imitating stuff I found in the webpack source code...

jedwards1211 commented 8 years ago

Okay it looks like it works with npm 3 but not npm 2, because of the way npm 2 structures the dependencies folders (and I haven't figured out how to specify the modules directories for loaders in webpack 2)

jedwards1211 commented 8 years ago

Okay, now I figured it out, I had to add a ModulesInRootPlugin for the node_modules in meteor-imports-webpack-plugin. I figured out how all this stuff works in Webpack 2 by looking at ResolverFactory -- basically it just applies plugins to the resolver for all of the items in your compiler.options.resolve.alias, compiler.options.resolve.modules, etc.

It checked on why adding items to the config like compiler.options.resolve.alias['meteor-imports'] = ... doesn't work in Webpack 2: it looks like it goes through the options and applies the corresponding plugins before even calling compiler.run(). Not sure how it worked in Webpack 1 but that explains why tweaking the options in this plugin didn't seem to have any effect on Webpack 2.

jedwards1211 commented 8 years ago

I have passing integration tests for crater using my webpack 2 fork of this plugin here :)

luisherranz commented 8 years ago

Amazing work @jedwards1211.

I'm away from the computer for 10 days but I've made you collaborator of this repo. Feel free to merge this or any other changes you think are useful.

If you tell me your npm username I'll add you there as well so you can publish new versions. I've searched for jedwards1211 but it doesn't exist.

Thanks for your work in this repo. Long life to OSS 😄🤘

jedwards1211 commented 8 years ago

Woohoo, thanks! I'll be back to work on Monday. I forget my npm username, haha, I'll look it up then.

jedwards1211 commented 8 years ago

So is it okay with you if we publish the webpack2-compatible branch as version 2.0.0-beta.X? Also, do you want me to merge this into master and have a webpack1 branch or would you rather put this in a webpack2 branch?

jedwards1211 commented 8 years ago

Weird, jedwards1211 is my npm username, not sure why you couldn't find it.

luisherranz commented 8 years ago

Weird, jedwards1211 is my npm username, not sure why you couldn't find it.

Maybe I made a typo, I don't know. It's working now!

So is it okay with you if we publish the webpack2-compatible branch as version 2.0.0-beta.X

Perfect.

Also, do you want me to merge this into master and have a webpack1 branch or would you rather put this in a webpack2 branch?

I think keeping it as a beta and using a webpack2 branch is better until webpack is officially released. We can add it to the README.

jedwards1211 commented 8 years ago

Yeah I agree, I'll try to finish this in a bit