我正在尝试使用'uglifyjs'将我的所有javascript文件缩小为一个'.js'文件,以便让karma ng-scenario e2e测试正常运行。但是当我输入这个
时type My.js MyLogon.js MyMenu.js Common\directives\BaseDirectives.js Common\factories\BaseFactories.js Module\AccountConfirmationModule.js Module\AccountModule.js Module\ApplicationModule.js Module\ApplicationRoleModule.js Module\HeaderModule.js Module\Index.js Module\LogOnModule.js Module\PasswordModule.js Module\QAModule.js Module\UsernameModule.js > files.min.js | uglifyjs -o files.min.js
我收到以下错误
Get-Content:找不到接受的位置参数 参数'MyLogon.js'。在行:1 char:5
我做错了什么?
答案 0 :(得分:2)
Cmd shell中的type
命令支持同时键入多个文件。文件名只是空格分隔。在Powershell中,type
是Get-Content
的别名。它支持多个源文件,但不使用空间分隔。需要一个数组,由支持String数组的-Path
参数指定:
man type
Get-Content [-Path] <string[]> [-Credential <PSCredential>] ...
尝试向cmdlet传递一个文件名数组。像这样,
type @("My.js", "MyLogon.js", "MyMenu.js") | uglifyjs -o files.min.js
答案 1 :(得分:0)
如果所有文件都在当前文件夹中,并且没有其他* .js文件:
if (test-path files.min.js) { remove-item files.min.js }
gci *.js | foreach{ type $_ >> files.min.js }
uglifyjs -o files.min.js
如果不是这种情况,可以这样设置列表:
$files = ("My.js", "MyLogon.js", "MyMenu.js", "Common\directives\BaseDirectives.js", "Common\factories\BaseFactories.js", "Module\AccountConfirmationModule.js", "Module\AccountModule.js", "Module\ApplicationModule.js", "Module\ApplicationRoleModule.js", "Module\HeaderModule.js", "Module\Index.js", "Module\LogOnModule.js", "Module\PasswordModule.js", "Module\QAModule.js", "Module\UsernameModule.js")
if (test-path files.min.js) { remove-item files.min.js }
$files | foreach{ type $_ >> files.min.js }
uglifyjs -o files.min.js
答案 2 :(得分:0)
在powershell中,列表以逗号分隔,而不是空格
type file1, file2, file3