Pregunta

I would like to pipe my .js files to uglifyjs using windows powershell.

This will not work:

dir .\build -filter *.js | uglifyjs > bundle.js

From the uglifyjs2 docs i can see that uglifyjs takes 2 parameters:

uglifyjs [input files] [options]

I have learned that i can use the pipe operator on functions with one parameter without modifications. But how should i handle 2 parameters?

Also, uglifyjs will write the result to STDOUT. That means that i can simply use > to write it to a file?

¿Fue útil?

Solución

It looks like uglifyjs can process multiple filenames or STDIN.

So I think you have two options:

Option 1 - Pipe the contents of the file into uglifyjs

dir .\build -filter *.js | Get-Content | uglifyjs -o bundle.js

Option 2 - Pass the filenames into uglifyjs

$files = (dir .\build -filter *.js | select -expandproperty Name) -Join " "    
uglifyjs $files -o bundle.js
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top