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..c86fa152b 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,10 @@ "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.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..920c02ed2 --- /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..9fc6d7a54 --- /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 : {}'; +}