如何将文件夹设置为 Angular-Cli 命令?

How to set folders to Angular-Cli commands?

这个问题是关于 angular-cli 用法的。

是否可以为 运行 ng 命令指定项目文件夹?

例如:

$ ng build /home/fadc80/my-first-angular-cli-project

此外...

是否也可以指定输出文件夹?

例如:

$ ng build /home/fadc80/my-first-angular-cli-project ./build

谢谢!

当您不在项目文件夹中时,无法直接构建 cli 项目。

Angular cli 退出并在此处显示一条有用的错误消息:

You have to be inside an angular-cli project in order to use the build command.

但是要实现你想做的事情,你可以这样做:

CURRENT_DIR=$(pwd) && \
cd /home/fadc80/my-first-angular-cli-project && \
ng build -o $CURRENT_DIR/build && \
cd $CURRENT_DIR

NOTE: This answer does not answer the actual question, but leaving it hear as the build param information may be helpful to those searching and ending up here.

apps 下的文件 angular-cli.json 中有一个名为 outDir 的 属性,其默认值为 dist

您可以自定义该值以将构建的输出放置在对您的项目最有意义的位置。

此外;您可以使用 output-path 选项通过命令行指定值:

ng build --output-path build

或通过快捷方式 o

ng build -o build