Closed pm64 closed 3 years ago
Should be possible using https://gulpjs.com/docs/en/getting-started/watching-files/
Thanks @w0rm, I understand that Gulp has its own built-in watching features, and that there are many ways of watching a file system from within a Gulp script. But I'm referring specifically to the PostCSS watching mechanism that things like Tailwind CSS's JIT compiler depend on. The solution you propose is not "equivalent" to postcss-cli's -w switch.
@pm64 it is functionally equivalent if your use case is watching for changes and recompiling css.
Each gulp plugin exports a transformation for a stream of files. Gulp loads the file contents (or watches for changes) and pipes them through this transformation.
@w0rm yes, the idea is similar, but it is not functionally equivalent, even in the narrow sense you describe. For example, take a system like Tailwind CSS JIT that is designed to be processed using the -w switch. You can achieve an approximate simulation of the build process using gulp-postcss with a Gulp watcher, as you mention. But in that case, the configuration and processing of source material happens completely differently than it would on the commandline with -w. Tailwind CSS JIT's own configuration with respect to file watching will be ignored, and all related optimizations are lost. For a Gulp-based solution to be equivalent to the commandline, PostCSS source material that expects to be processed from the commandline must not care that it's being processed from Gulp.
@pm64 but that's just how gulp pipelines are designed. If this doesn't work in your case, and you cannot avoid using gulp, then it should be possible to create a gulp task that runs cli. Not everything has to be a gulp plugin.
Fair point, thanks @w0rm.
As far as I can tell, it is not possible to use gulp-postcss to run PostCSS in "watch" mode, as when the "-w" switch is passed to postcss-cli on the commandline. In a perfect world, this mode would be supported by gulp-postcss, which would send output through the rest of the PostCSS pipeline, then through the rest of the Gulp pipeline, each time output is generated.