Would anyone know how I can pipe output from Watchify to eslint - and have it report linting issues in the CLI while still building the outputted JS ?
Watchify states that you can pipe to a command using -o
.
watchify main.js -o 'uglifyjs -cm > static/bundle.min.js'
Eslint says you can read from stdin by using the --stdin
flag.
So with this knowledge I'm using the following command:
watchify main.js -o 'eslint --stdin > static/bundle.js'
What this actually does is output eslint warnings to static/bundle.js
.
I'd still like it to report to the CLI yet build the JS when linting passes. Is that possible?
I'm just looking for a CLI solution using the modules directly. I'm not planning on using Gulp/Grunt or equivalent.
Watchify, unfortunately, requires that you specify an output file, meaning that you'll be unable to stream/pipe the --stdin
flag from eslint to watchify output.
In order to use the --stdin
flag, the input must be in the form of a previous command that resulted in output to the shell's stdout
. eslint would then take that data, and lint it, sending the output of the eslint command only, to the systems stdout
... which is what you see when eslint responds with any problems or successes.
Since watchify is bundling your source files, it's probably a better idea to lint first, and then execute watchify. Alternatively, you could do both at the same time. Here are examples of each:
eslint first:
eslint /path/to/src && watchify watchify main.js -o 'uglifyjs -cm > static/bundle.min.js'
concurrently:
eslint /path/to/src & watchify watchify main.js -o 'uglifyjs -cm > static/bundle.min.js'