Skip to content

Commit 590bbb2

Browse files
Jeremy JudeauxJeremy Judeaux
authored andcommitted
Serve sockjs.js from sockjs-client dependency, don't use default from CDN
1 parent dd61b99 commit 590bbb2

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
/client/live.bundle.js
3-
/client/index.bundle.js
3+
/client/index.bundle.js
4+
/client/sockjs.bundle.js

client/sockjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('sockjs-client');

client/webpack.sockjs.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
output: {
3+
library: "SockJS",
4+
libraryTarget: "umd"
5+
}
6+
}

lib/Server.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function Server(compiler, options) {
4646
var inlinedJs = new StreamCache();
4747
fs.createReadStream(path.join(__dirname, "..", "client", "index.bundle.js")).pipe(inlinedJs);
4848

49+
// Prepare the sockjs js file
50+
var sockjsJs = new StreamCache();
51+
fs.createReadStream(path.join(__dirname, "..", "client", "sockjs.bundle.js")).pipe(sockjsJs);
52+
4953
// Init express server
5054
var app = this.app = new express();
5155

@@ -57,6 +61,11 @@ function Server(compiler, options) {
5761
liveJs.pipe(res);
5862
});
5963

64+
app.get("/__webpack_dev_server__/sockjs.bundle.js", function(req, res) {
65+
res.setHeader("Content-Type", "application/javascript");
66+
sockjsJs.pipe(res);
67+
});
68+
6069
app.get("/webpack-dev-server.js", function(req, res) {
6170
res.setHeader("Content-Type", "application/javascript");
6271
inlinedJs.pipe(res);
@@ -318,7 +327,9 @@ Server.prototype.listen = function() {
318327
if(severity === "error") {
319328
console.log(line);
320329
}
321-
}
330+
},
331+
// Use provided up-to-date sockjs-client
332+
sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js"
322333
});
323334
sockServer.on("connection", function(conn) {
324335
this.sockets.push(conn);

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
"ssl/"
5353
],
5454
"scripts": {
55-
"prepublish": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p && webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p",
55+
"prepublish": "npm run webpack-live && npm run webpack-index && npm run webpack-sockjs",
56+
"webpack-live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p",
57+
"webpack-index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p",
58+
"webpack-sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p",
5659
"lint": "eslint lib test",
5760
"beautify-lint": "beautify-lint lib/**.js bin/**.js",
5861
"beautify": "beautify-rewrite lib/**.js bin/**.js",

0 commit comments

Comments
 (0)