문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top