3

I'm trying to create a powershell alias for my ng build command which is fairly long.

node --max_old_space_size=4096 .\node_modules\@angular\cli\bin\ng build --configuration=debug --watch

Aliasing the command directly using Set-Alias -Name ngBuild -Value node --max_old_space_size=4096 .\node_modules\@angular\cli\bin\ng build --configuration=debug --watch doesn't work for me.

Chris S.
  • 31
  • 2
  • 1
    `Set-Alias` is meant for cmdlets / functions, not to store `scriptblocks`. I guess, an option you have is to store your command inside a function with that name you wanted. – Santiago Squarzon May 06 '21 at 21:57
  • You can make a function with the command, and even make an alias for that command. – Abraham Zinala May 06 '21 at 21:57
  • @Santago ALWAYS seconds ahead of me haha – Abraham Zinala May 06 '21 at 21:58
  • 1
    In short: Unlike in POSIX-compatible shells such as `bash`, you _cannot include pass-through arguments_ in a PowerShell alias definition - you need a _function_ for that. PowerShell aliases are simply _alternative names_ for other commands, with no ability to "bake in" arguments. E.g., to define a short command `bar` that invokes command `foo` with fixed argument `bar` while passing all other arguments through, use `function bar { foo bar @args }` - see the [linked duplicate](https://stackoverflow.com/a/55539863/45375) for more information. – mklement0 May 06 '21 at 22:09

0 Answers0