Skip to content
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

browserify 2 support #13

Open
jhnns opened this issue Feb 23, 2013 · 66 comments
Open

browserify 2 support #13

jhnns opened this issue Feb 23, 2013 · 66 comments
Assignees
Labels

Comments

@jhnns
Copy link
Owner

jhnns commented Feb 23, 2013

If anyone wants to have browserify 2 support, let me know.

@ghost ghost assigned jhnns Feb 23, 2013
@jhnns
Copy link
Owner Author

jhnns commented Feb 23, 2013

Everything rewire needs is bundler-independent, so it basically "just" has to be adapted to the new browserify api. But since I'm not using browserify anymore I'm currently not implementing it.

@aleclofabbro
Copy link

you prefer webpack, i guess .. (i see you developed an adapter)
why?
i'm using browserify, i don't know webpack
iyho, whats worth for me? learning fast webpack or write an adapter for rewire?

@jhnns
Copy link
Owner Author

jhnns commented Oct 1, 2013

Did you use the browserify plugin? Did it work with browserify 2 as well? Or do you still use browserify 1?

Personally I prefer webpack, because it is more flexible. It comes with many loaders (like CoffeeScript, LESS, style, mocha) and supports different styles (commonjs, amd, components). But since browserify 2 a lot has changed, so browserify might be as good as webpack.

webpack's documentation is still in progress, but the maintainer @sokra is responding fast so this was not an issue for me.

@sokra
Copy link
Contributor

sokra commented Oct 1, 2013

I was mentioned... (Just to prove that I'll respond fast 😄)

@tphummel
Copy link

👍

3 similar comments
@davidguttman
Copy link

👍

@jbaiter
Copy link

jbaiter commented Mar 25, 2014

👍

@focusaurus
Copy link

👍

@i-like-robots
Copy link

Because I really needed something like Rewire for Browserify I went ahead and did the port, so far it's been working out nicely: https://github.com/i-like-robots/rewireify

@jprichardson
Copy link

👍

@jhnns
Copy link
Owner Author

jhnns commented Apr 16, 2014

@i-like-robots Cool! Since I'm not using browserify anymore I'm not too motivated to write a plugin 😉.

Your implementation is simple and straight-forward. It doesn't work exactly like rewire, but that's ok for client-side modules. It will be a problem for isomorphic modules that run in node.js and in the browser. That's why I decided to stick straight to the node-rewire API for my webpack plugin.

If you're planing to rewrite rewireify to be compatible to the node-rewire API here's some advice:

Rewire circumvents the require.cache so other modules don't require the rewired version. Additionally every rewire()-call creates a new module instance. Furthermore a call of rewire("./moduleA.js") needs to add moduleA as dependency to the bundle. I don't know if browserify exposes the parser api to hack in these kind of things. Concerning globals I think you should also prepend the getImportGlobalsSrc()-content. If you add rewire as dependency of rewireify you can just require all the rewire utility modules like __get__, __set__, getImportGlobalsSrc and detectStrictMode.

Back in the browserify 1 days I hacked a browserify plugin for rewire. May that's some inspiration (although there were some crazy hacks necessary because browserify didn't provide an useful api).

@i-like-robots
Copy link

@jhnns Thanks for more information, that's really helpful. I put this together extremely quickly as a proof of concept but I plan on working on it to make it more robust. I studied your implementation thoroughly and it was interesting working out how to lever it into Browserify. Unfortunately Browserify does not readily expose a require function to override but I think I can definitely improve on simply injecting the functions into each and every module!

@jhnns
Copy link
Owner Author

jhnns commented Apr 16, 2014

Well, you could just take my browserify 1 middleware and adjust it to the new transform api of browserify > 2. All the magic/crazy client-side stuff should still work. You just need to find the browserify-2-equivalents of bundle.register and bundle.require.

@i-like-robots
Copy link

That covers a lot of the things I've been thinking about, glad to see some of this stuff has already been solved! Thanks for digging that out for me.

@jhnns
Copy link
Owner Author

jhnns commented Apr 22, 2014

Could you make any progress yet?

@jsdf
Copy link

jsdf commented Jun 28, 2014

👍

@wookiehangover
Copy link

👍

@benatkin
Copy link

benatkin commented Jul 9, 2014

👍

1 similar comment
@iamrandys
Copy link

👍

@iamrandys
Copy link

Thanks @i-like-robots!! Your rewireify works perfectly! I simply added it to my karma.conf and presto! Thanks again!

    browserify: {
        debug: true,
        transform: [ 'reactify', 'rewireify' ]
    },

https://github.com/i-like-robots/rewireify

@jhnns
Copy link
Owner Author

jhnns commented Aug 14, 2014

Yep, it's cool. Just wanted to point out that the implementation differs a bit (see above).

@iamrandys
Copy link

👍

Ah as you stated, I see that rewire is clearing the require cache each time and returning a fresh instance. This is very important when developing unit tests. Rewireify is really close, but my unit tests are failing using because they are all using the same "required" instance and my mock call counts are not as expected when running multiple tests together. If I run the tests one at a time they run fine.

Rewire is exactly what browserify needs, but I don't see any way to clear the require cache in browserify.

Difference to require()

Every call of rewire() executes the module again and returns a fresh instance.

rewire("./myModule.js") === rewire("./myModule.js"); // = false


Furthermore a call of rewire("./moduleA.js") needs to add moduleA as dependency to the bundle.

I can easily add moduleA as a dependency in Browserify by calling bundler.require('/moduleA.js', {expose: './moduleA.js').

@traviskaufman
Copy link

👍

@jhnns
Copy link
Owner Author

jhnns commented Sep 8, 2014

There's no require.cache in browserify? They somehow must have reverted my pull-request with browserify 2...

@blairanderson
Copy link

i want browserify support

@danielyogel
Copy link

Browserify support would be great. Thanks!

@thom4parisot
Copy link

Pretty much interested by this feature to reuse my tests in karma as well 👍

@jonykrause
Copy link

👍

@cyrilthomas
Copy link

how about requirejs?

@mik01aj
Copy link

mik01aj commented Feb 18, 2015

+1

EDIT: I found https://github.com/i-like-robots/rewireify, which does the job for me. Thanks @i-like-robots !

@Prestaul
Copy link

👍 Yes, please. A fully compatible browserify transform would be awesome.

@jhnns
Copy link
Owner Author

jhnns commented Feb 22, 2015

@mik01aj Please be aware that rewireify doesn't mimic rewire exactly. Code that runs in node might break in the browser. However, if it's working for you, that's just fine 😁

@pjanuario
Copy link

Hi, I am working in some isomorphic code with rendrjs and stumble with this issue of using rewirefy with browserify 3 and karma. Any one was able to make this work on karma?

By the way, nice job with this module it's seems to work really nice on node.

@Josh-a-e
Copy link

+1

3 similar comments
@iamrandys
Copy link

+1

@nsonnad
Copy link

nsonnad commented Apr 15, 2015

+1

@revolunet
Copy link

👍

@stuff
Copy link

stuff commented May 4, 2015

👍 I think we need an official browserify support...

@joswhite
Copy link

joswhite commented May 4, 2015

Edit: This would be cool, but I found that webpack actually does the job a bit cleaner. All you have to do is add the few lines to your config file. If you are using Node you'll also need to specify empty modules for fs, etc. This is my config file.

var RewirePlugin = require("rewire-webpack");
module.exports = {
    plugins: [
        new RewirePlugin()
    ],
    node: {
        child_process:"empty",
        fs: "empty"
    }
};

@allenm
Copy link

allenm commented May 6, 2015

+1

1 similar comment
@aroc
Copy link

aroc commented May 26, 2015

👍

@djforth
Copy link

djforth commented May 26, 2015

  • 1

@kvintessents
Copy link

+1

9 similar comments
@BenGedi
Copy link

BenGedi commented Jun 10, 2015

👍

@michaelobriena
Copy link

+1

@nicbarker
Copy link

+1

@ariporad
Copy link

+1

@danillouz
Copy link

+1

@tran2
Copy link

tran2 commented Jul 17, 2015

+1

@evanroane
Copy link

+1

@rikutiira
Copy link

+1

@mcabrams
Copy link

+1

@iamrandys
Copy link

No matter how many +1s, it'll never happen ;) I've seen the +1s for months now... I believe rewirify uses rewire now?

@belen-albeza
Copy link

+1

3 similar comments
@vdininski
Copy link

👍

@applesaucesome
Copy link

+1

@JoshuaToenyes
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests