dart-sass icon indicating copy to clipboard operation
dart-sass copied to clipboard

Lazy load chokidar dependency

Open eklingen opened this issue 6 years ago • 5 comments

Is it possible to make dart-sass load chokidar only when actually watching files?

In trying to optimise my build chain, I've noticed dart-sass loads the chokidar dependency, even when the watch functionality isn't actually used. While the absolute timings are small (though depending on cpu, I/O, etc), chokidar is relatively heavy, since it accounts for ~75% of the time it takes to load dart-sass. At least, in my tests.

   55 ms        │   ├─ node_modules/sass/sass.dart.js (2x)
   43 ms        │   │   └─ node_modules/chokidar/index.js (10x)
    4 ms        │   │       ├─ node_modules/readdirp/index.js (2x)
    4 ms        │   │       │   └─ node_modules/picomatch/index.js
   18 ms        │   │       ├─ node_modules/chokidar/node_modules/braces/index.js (4x)
    4 ms        │   │       │   └─ node_modules/chokidar/node_modules/braces/lib/compile.js (2x)
    9 ms        │   │       └─ node_modules/chokidar/lib/fsevents-handler.js (2x)
    8 ms        │   │           └─ node_modules/fsevents/fsevents.js

I'm not that well versed in Dart. But i'm willing to take a crack at it.

eklingen avatar Oct 27 '19 11:10 eklingen

My understanding is that lazy-loading dependencies works poorly with WebPack's bundling (https://github.com/sass/dart-sass/issues/726). If we can find a way to resolve these two issues, I'm open to lazily loading Chokidar again.

nex3 avatar Oct 29 '19 18:10 nex3

Might be worth upgrading to chokidar 3.x since it is about an 17x package & deps size reduction compared to 2.x. so it might load faster

DRoet avatar Dec 23 '19 09:12 DRoet

Looks like support for 3.x has been in place since https://github.com/sass/dart-sass/pull/731, corresponding I think to version v1.22.1:

https://github.com/sass/dart-sass/blob/d155f3518e92a1b41122f0f2e3b22572329c35c6/package/package.json#L19-L21

tchetwin avatar May 26 '20 15:05 tchetwin

I don't think its being honored then, because it only installs the latest version of 2... 2.1.8......

Fresh install shows

├─┬ [email protected]
│ └─┬ [email protected]

changing the package.json of sass to ">=3.0.0 <4.0.0" correctly installs the latest version

I'm getting problems on Mac's because its the only dependency that installs fsevents version 1, and it doesn't work with NodeJS 14.

dl748 avatar Feb 16 '21 23:02 dl748

As Node.js 14 is already in LTS mode and chokidar 2.x breaks on Node 14, I think it's time for chokidar 3.x. This actually prevents me to upgrade to Node 14 for my apps.

silviuburceadev avatar Mar 31 '21 09:03 silviuburceadev