Skip to content

Commit

Permalink
[docs] Update webpack example (socketio#2960)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne authored Jun 3, 2017
1 parent 1690329 commit a60d82e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
4 changes: 3 additions & 1 deletion examples/webpack-build/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

var socket = require('socket.io-client')('http://localhost:3000');
import io from 'socket.io-client';

const socket = io('http://localhost:3000');

console.log('init');

Expand Down
8 changes: 5 additions & 3 deletions examples/webpack-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"scripts": {
"build": "webpack --config ./support/webpack.config.js",
"build-slim": "webpack --config ./support/webpack.config.slim.js",
"build-all": "npm run build && npm run build-slim"
"build-json-parser": "webpack --config ./support/webpack.config.json-parser.js",
"build-all": "npm run build && npm run build-slim && npm run build-json-parser"
},
"author": "Damien Arrachequesne",
"license": "MIT",
"dependencies": {
"socket.io-client": "^1.7.2"
"socket.io-client": "^2.0.2",
"socket.io-json-parser": "^2.1.0"
},
"devDependencies": {
"strip-loader": "^0.1.2",
"webpack": "^1.14.0"
"webpack": "^2.6.1"
}
}
4 changes: 2 additions & 2 deletions examples/webpack-build/support/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
entry: './lib/index.js',
output: {
path: './dist',
path: require('path').join(__dirname, '../dist'),
filename: 'app.js'
},
}
};
33 changes: 33 additions & 0 deletions examples/webpack-build/support/webpack.config.json-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

var webpack = require('webpack');

module.exports = {
entry: './lib/index.js',
output: {
path: require('path').join(__dirname, '../dist'),
filename: 'app.json-parser.js'
},
// generate sourcemap
devtool: 'source-map',
plugins: [
// replace require('debug')() with an noop function
new webpack.NormalModuleReplacementPlugin(/debug/, process.cwd() + '/support/noop.js'),
// replace socket.io-parser with socket.io-json-parser
new webpack.NormalModuleReplacementPlugin(/socket\.io-parser/, 'socket.io-json-parser'),
// use uglifyJS (IE9+ support)
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
],
module: {
loaders: [
{
// strip `debug()` calls
test: /\.js$/,
loader: 'strip-loader?strip[]=debug'
}
]
}
};
6 changes: 1 addition & 5 deletions examples/webpack-build/support/webpack.config.slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ var webpack = require('webpack');
module.exports = {
entry: './lib/index.js',
output: {
path: './dist',
path: require('path').join(__dirname, '../dist'),
filename: 'app.slim.js'
},
externals: {
// replace JSON polyfill (IE6/IE7) with global JSON object
json3: 'JSON'
},
// generate sourcemap
devtool: 'source-map',
plugins: [
Expand Down
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var read = require('fs').readFileSync;
var path = require('path');
var exists = require('fs').existsSync;
var engine = require('engine.io');
var client = require('socket.io-client');
var clientVersion = require('socket.io-client/package').version;
var clientVersion = require('socket.io-client/package.json').version;
var Client = require('./client');
var Emitter = require('events').EventEmitter;
var Namespace = require('./namespace');
Expand Down

0 comments on commit a60d82e

Please sign in to comment.