From 07717c252638ab935f3e067063c1124307f99670 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 25 Nov 2016 23:46:30 +0100 Subject: [PATCH 1/2] Provide a slim build without JSON3 and debug --- gulpfile.js | 7 +++++- package.json | 2 +- support/noop.js | 2 ++ support/webpack.config.js | 1 + support/webpack.config.slim.js | 45 ++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 support/noop.js create mode 100644 support/webpack.config.slim.js diff --git a/gulpfile.js b/gulpfile.js index cd133716e..fef735230 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,7 +19,12 @@ const BUILD_TARGET_DIR = './dist/'; gulp.task('build', function () { return gulp.src('lib/*.js') - .pipe(webpack(require('./support/webpack.config.js'))) + .pipe(webpack({ + config: [ + require('./support/webpack.config.js'), + require('./support/webpack.config.slim.js') + ] + })) .pipe(minify({ ext: { src: '.js', diff --git a/package.json b/package.json index 01a137d4f..7bea7c49c 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "socket.io": "1.6.0", "text-blob-builder": "0.0.1", "uglify-js": "2.6.1", - "webpack-stream": "3.1.0", + "webpack-stream": "3.2.0", "zuul": "3.11.0", "zuul-builder-webpack": "1.1.0", "zuul-ngrok": "4.0.0" diff --git a/support/noop.js b/support/noop.js new file mode 100644 index 000000000..576834d7f --- /dev/null +++ b/support/noop.js @@ -0,0 +1,2 @@ + +module.exports = function() { return function () {} }; diff --git a/support/webpack.config.js b/support/webpack.config.js index dbac096c2..c93314987 100644 --- a/support/webpack.config.js +++ b/support/webpack.config.js @@ -1,5 +1,6 @@ module.exports = { + name: 'default', entry: './lib/index.js', output: { library: 'io', diff --git a/support/webpack.config.slim.js b/support/webpack.config.slim.js new file mode 100644 index 000000000..de5372dc4 --- /dev/null +++ b/support/webpack.config.slim.js @@ -0,0 +1,45 @@ + +var webpack = require('webpack'); + +module.exports = { + name: 'slim', + entry: './lib/index.js', + output: { + library: 'io', + libraryTarget: 'umd', + filename: 'socket.io.slim.js' + }, + externals: { + global: glob() + }, + devtool: 'cheap-module-source-map', + plugins: [ + new webpack.NormalModuleReplacementPlugin(/(debug|json3)/, process.cwd() + '/support/noop.js') + ], + module: { + loaders: [{ + test: /\.js$/, + exclude: /(node_modules|bower_components)/, + loader: 'babel', // 'babel-loader' is also a legal name to reference + query: { presets: ['es2015'] } + }, { + test: /\json3.js/, + loader: 'imports?define=>false' + }, { + test: /\.js$/, + loader: "strip-loader?strip[]=debug" + }] + } +}; + +/** + * Populates `global`. + * + * @api private + */ + +function glob () { + return 'typeof self !== "undefined" ? self : ' + + 'typeof window !== "undefined" ? window : ' + + 'typeof global !== "undefined" ? global : {}'; +} From 4bf862f18ce2b7cb3ac5a70efd7958fee1e9031f Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sat, 26 Nov 2016 19:14:22 +0100 Subject: [PATCH 2/2] fix style --- package.json | 1 + support/noop.js | 2 +- support/webpack.config.slim.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7bea7c49c..c86fa152b 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "istanbul": "0.4.2", "mocha": "2.3.4", "socket.io": "1.6.0", + "strip-loader": "0.1.2", "text-blob-builder": "0.0.1", "uglify-js": "2.6.1", "webpack-stream": "3.2.0", diff --git a/support/noop.js b/support/noop.js index 576834d7f..920c02ed2 100644 --- a/support/noop.js +++ b/support/noop.js @@ -1,2 +1,2 @@ -module.exports = function() { return function () {} }; +module.exports = function () { return function () {}; }; diff --git a/support/webpack.config.slim.js b/support/webpack.config.slim.js index de5372dc4..9fc6d7a54 100644 --- a/support/webpack.config.slim.js +++ b/support/webpack.config.slim.js @@ -27,7 +27,7 @@ module.exports = { loader: 'imports?define=>false' }, { test: /\.js$/, - loader: "strip-loader?strip[]=debug" + loader: 'strip-loader?strip[]=debug' }] } };