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

Replace socket.io with SockJS as discussed in #229 #302

Merged
merged 7 commits into from
Nov 24, 2015

Conversation

SpaceK33z
Copy link
Member

The socket.io dependency causes node-gyp to be used. This results in a lot of issues with Windows and Linux installs. SockJS is much, much lighter and is node-only. This also results in a 5mb package size decrease :).

This is a relatively big change, so it would be best if some people test this in their project.

Fixes #229, #276, fixes #195, fixes #267, fixes #258 and fixes #242

This removes the node-gyp dependency :).

Fixes webpack#229, webpack#276, fixes webpack#195, fixes webpack#267, fixes webpack#258 and fixes webpack#242

// Try to reconnect.
sock = null;
recInterval = setInterval(function () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are clearing the interval immediately on execution, why not just:

recTimeout = setTimeout(newConnection, 2000, handlers);

Since newConnection is only called once, the clearInterval is not needed. Same for the other thing in live.js.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this is fixed now.

@cristisp
Copy link

+1 for replacing Socket.io with something more lightweight :)

@aromot
Copy link

aromot commented Oct 28, 2015

I have the same problem. How to replace socket.io with SockJS?

@SpaceK33z
Copy link
Member Author

@aromot, you'll have to wait until this PR is merged and released.

@mathieumg
Copy link

@SpaceK33z This would be a welcome change! Is there some sort of built version somewhere, or is using https://github.com/CodeYellowBV/webpack-dev-server/tree/sockjs as the dependency sufficient? What versions of Node are supported?

@@ -146,7 +151,7 @@ function Server(compiler, options) {
}
proxy.web(req, res, proxyOptions, function(err){
var msg = "cannot proxy to " + proxyOptions.target + " (" + err.message + ")";
this.io.sockets.emit("proxy-error", [msg]);
this.sockWrite("proxy-error", [msg]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be guarded with a verification that this.sock exists? I get a crash when this runs because this.sock is undefined in the this.sockWrite call. Perhaps that guard should simply be put inside the sockWrite call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a guard inside of sockWrite

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was added following my remark. :) See CodeYellowBV@a5ddf82

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@SpaceK33z
Copy link
Member Author

@mathieumg Looking at the package.json of webpack-dev-server, it runs a prepublish script. So that would mean you need a pre-built version.

You could test it manually by adding my github repo as a dependency, npm install-ing and running npm run prepublish in node_modules/webpack-dev-server. This would be only to test this PR of course. I would really like it if you do this, because this PR is relatively big. Please report your findings here :).

I can't find the exact node version requirements for the sockjs-node package, but it works fine for at least v0.12 and v4.x.

@mathieumg
Copy link

Yeah I had figured that in the meantime! :) I did and I got a crash, I pointed where in the review, above!

@SpaceK33z
Copy link
Member Author

@mathieumg, could you try again? I have probably fixed your issue. Weirdly enough I never had this issue. And thanks for testing, I appreciate it :).

@mathieumg
Copy link

@SpaceK33z Everything works perfectly with the latest fix! :)

@nelix
Copy link
Contributor

nelix commented Nov 10, 2015

What about server sent events, should be simpler and a small dependency for one way notifications.

https://github.com/glenjamin/webpack-hot-middleware uses SSE and the code looks really simple.

SSE should be easy to polyfill anywhere that has http.

@cristisp
Copy link

@sokra Could we hear your opinion on this PR? It would solve the issue with dependency on the github package from socket.io and would be more lightweight.

if (this.sock) {
this.sock.write(JSON.stringify({type: type, data: data}));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this function into the prototype of the class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed that now.

this.io.sockets.on("connection", function(socket) {
if(this.hot) socket.emit("hot");
sockServer.on("connection", function(conn) {
this.sock = conn;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to connect multiple devices to the same dev-server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, this could also be the reason that a re-connect doesn't emit an ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was a pretty big oversight of me. Pretty ashamed I didn't notice that myself. Anyway, it should be fixed now.

@eladh
Copy link

eladh commented Nov 19, 2015

hi @SpaceK33z

also checked the fix and the webpack dev server is up and running on windows.

any idea when the fixed will be merged and published ?

10x

@SpaceK33z
Copy link
Member Author

@eladh, I have now fixed @sokra's concerns, but I can't tell you when it's getting published of course.

@sokra
Copy link
Member

sokra commented Nov 21, 2015

Looks fine now... I'll test it and eventually merge it. Please ping me in a week if I forget it...

@CREATE-AI
Copy link

+1 wait for it.

@eladh
Copy link

eladh commented Nov 24, 2015

Important update - in the latest version of Artifactory there is support for this kind of problems (direct http or github resources) via the NPM/Bower

https://www.jfrog.com/jira/browse/RTFACT-7664

sokra added a commit that referenced this pull request Nov 24, 2015
Replace socket.io with SockJS as discussed in #229
@sokra sokra merged commit 68242b3 into webpack:master Nov 24, 2015
@sokra
Copy link
Member

sokra commented Nov 24, 2015

Thanks 👍

pretty good change, finally we get rid of the native dependency...

@cristisp
Copy link

Great job guys! Thank you!

@mathieumg
Copy link

Awesome! 🎉

@eladh
Copy link

eladh commented Nov 24, 2015

thanks :-)

@abzainuddin
Copy link

\o/

@CREATE-AI
Copy link

thanks

@fusepilot
Copy link

How does this fix #276? Theres still a ton of client side logging and I dont see how to disable it.

screenshot 2015-12-03 00 59 45

@SpaceK33z
Copy link
Member Author

Yeah that's because you have enabled it in your localStorage. Open the console and type: localStorage.removeItem('debug')

If you want debugging logs again: localStorage.setItem('debug', '*')

@fusepilot
Copy link

That was it, thanks!

This was referenced Dec 5, 2015
var currentHash = "";

var newConnection = function(handlers) {
sock = new SockJS('/sockjs-node');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to flag that this breaks certain usage that relied on the previous /socket.io path. They now have to be /sockjs-node. Should this have been a major version bump, according to semver?

@muzishuiji
Copy link

i still do not know how to solve my trouble, it means that i should get the latest version of webpack-dev-server? or?

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