'ng build' 包含子文件夹中的所有脚本

kri*_*_IV 6 javascript angular-cli angular

现在可以使用 来获得非平面的项目结构ng build,而不是这样:

index.html  
main.bundle.js  
styles.bundle.js  
...
Run Code Online (Sandbox Code Playgroud)

我希望脚本位于子文件夹中

index.html  
scripts/main.bundle.js  
scripts/styles.bundle.js  
...
Run Code Online (Sandbox Code Playgroud)

我找到了一个关于此的主题:“ng build”将脚本移动到子文件夹但租用解决方案是ejectcli进入项目webpackAngular 7此不再可用,ng eject现在已禁用:

'eject' 命令已被禁用,将在 8.0 中完全删除。新的配置格式提供了更大的灵活性,无需弹出即可修改工作区的配置。

有几个项目可以与新的配置格式结合使用,提供弹出的好处而无需维护开销。一个这样的项目是 ngx-build-plus 在这里找到:https : //github.com/manfredsteyer/ngx-build-plus

Angular 提供的angular.json文件租用文档非常差https://github.com/angular/angular-cli/wiki/angular-workspace因此很难在实际项目问题中使用此配置文件。

Lui*_*mas 11

你不能ng build单独使用命令来做到这一点,你可以通过一个接一个地使用以下命令来做到这一点。

ng build --output-path="dist/scripts" --deployUrl="scripts/"
Run Code Online (Sandbox Code Playgroud)

move "dist\scripts\index.html" "dist"
Run Code Online (Sandbox Code Playgroud)

考虑到您使用的是 Windows,最后一个命令有效(只是复制/粘贴,魔术是由--deployUrl命令完成的)。

正如@Nick 在评论中所述,这options也可以添加到您的angular.json文件中:

ng build --output-path="dist/scripts" --deployUrl="scripts/"
Run Code Online (Sandbox Code Playgroud)