1

When I import(ES6) or require(CommonJS) a package installed by npm, is it possbile to specify the slim version ?

For example I npm install socket.io-client, socket.io-client provides socket.io.slim.js & socket.io.dev.js according to https://socket.io/docs/v2/client-installation/ I use ES6 import import io from 'socket.io-client' in my code.

Is it possbile to use socket.io.dev.js for development and socket.io.slim.js for production ?

I use webpack to bundle the code. I can't find the options to let webpack use socket.io.slim.js instead of socket.io.js. The build mode won't work because that will only use the "normal"production version socket.io.js not the slim version.

BTW, I am not sure if .slim.js is a standard name extension for javascript library, but it seems to be introduced by jQuery as a build without some extensions, as discusses here What is slim in file.slim.js. For socket.io.slim.js is the " Production version, without debug"

Qiulang
  • 10,295
  • 11
  • 80
  • 129
  • Why? The size of the dependency on the server almost certainly doesn't matter, and for things like the example you're using, socket.io already gives you every version during install, so you can then forward the most suitable version for clients (not your server) as needed by you. As for "is possible to [...]": yes. That's what your [build mode](https://webpack.js.org/configuration/mode/) is for. – Mike 'Pomax' Kamermans Jul 20 '21 at 04:38
  • I don't want debug package bundled in socket.io.js. But that is another question. – Qiulang Jul 20 '21 at 04:57
  • I remember I tried build mode and it didn't work. I will double check – Qiulang Jul 20 '21 at 04:59
  • @Mike'Pomax'Kamermans I have double checked that build mode will use the “normal” version not the slim version. I updated my question to make it more clearer. – Qiulang Jul 20 '21 at 06:15
  • Again though: why? The regular version is 19kb, the slim version is 15kb, that is a meaningless difference. However, if you need it to work client-side, then have a look at telling webpack that [your library is external](https://webpack.js.org/configuration/externals/) and that you're going to make sure it has a ` – Mike 'Pomax' Kamermans Jul 20 '21 at 14:32
  • It is a long story but take a look at these 2 issues if you are really interested https://github.com/visionmedia/debug/issues/729 & https://github.com/socketio/socket.io-client/issues/1328 – Qiulang Jul 20 '21 at 14:35
  • I don't, "the regular version doesn't work in IE11 and slim does" is good enough (if that's actually true). These issues don't explain why you anyone would need slim, rather than the regular version though, but as with anything that you want to explicitly load in the browser when it comes to webpack, externals lets you do that. – Mike 'Pomax' Kamermans Jul 20 '21 at 14:36
  • Fare enough, but I was a bit curious that the size was definitely not my concern. Isn't that obvious ? – Qiulang Jul 20 '21 at 14:41
  • I also had updated my question to mention "For socket.io.slim.js is the " Production version, without debug" – Qiulang Jul 20 '21 at 14:42
  • that's a good update. Externals should work just fine then. – Mike 'Pomax' Kamermans Jul 20 '21 at 14:45

0 Answers0