'ng build' 包含子文件夹中的所有脚本 [英] 'ng build' with all scripts in subfolder
问题描述
现在可以使用 ng build
获得非平面的项目结构,而不是这样:
It is now possible, to get not flat structure of project with ng build
, so instead of this:
index.html
main.bundle.js
styles.bundle.js
...
我希望脚本位于子文件夹中
I want scripts to be in subfolder
index.html
scripts/main.bundle.js
scripts/styles.bundle.js
...
我找到了一个关于此的主题:'ng build' move scripts to subfolder 但采用的解决方案是将 eject
项目从 cli
导入 webpack
但使用 Angular 7
这不再是可用并且 ng 弹出
现在已禁用:
I found a topic about this: 'ng build' move scripts to subfolder but hire the solutions is to eject
project from cli
into webpack
but with Angular 7
this is not longer available and ng eject
is now disabled:
'eject' 命令已被禁用,将被完全删除在 8.0.新的配置格式提供了更大的灵活性无需弹出即可修改工作区的配置.
The 'eject' command has been disabled and will be removed completely in 8.0. The new configuration format provides increased flexibility to modify the configuration of your workspace without ejecting.
有几个项目可以与新的结合使用提供退出的好处的配置格式维护开销.一个这样的项目是 ngx-build-plus 在这里找到:https://github.com/manfredsteyer/ngx-build-plus
There are several projects that can be used in conjuction with the new configuration format that provide the benefits of ejecting without the maintenance overhead. One such project is ngx-build-plus found here: https://github.com/manfredsteyer/ngx-build-plus
Angular 提供了非常差的 angular.json
文件租用文档 https://github.com/angular/angular-cli/wiki/angular-workspace 所以在实际项目问题中很难使用这个配置文件.
Angular provide very poor documentation of angular.json
file hire https://github.com/angular/angular-cli/wiki/angular-workspace so it's difficult to use this config file in real project problems.
推荐答案
你不能通过使用 ng build
命令,您可以依次使用以下命令.
You cannot do that by using the ng build
command alone, you can do it by using the following the commands one after the other.
ng build --output-path="dist/scripts" --deployUrl="scripts/"
和
move "dist\scripts\index.html" "dist"
考虑到您使用的是 Windows,最后一个命令有效(只是复制/粘贴,魔术由 --deployUrl
命令完成).
The last command works considering that you are using windows (is just a copy/paste, the magic is done by the --deployUrl
command).
正如@Nick 在评论中所说,这个 options
也可以添加到你的 angular.json
文件中:
As stated by @Nick in comments, this options
can also be added on your angular.json
file:
...
projects: {
angular: {
architect: {
build: {
options: {
outputPath: "dist/scripts",
deployUrl: "scripts/"
}
}
}
}
}
21 年 9 月 9 日更新:Angular 将他们的文档从 --deployUrl
更新为 --deploy-url
,它们的工作原理相同
Update 09/09/21:
Angular updated their documentation from --deployUrl
to --deploy-url
, they work the same
这篇关于'ng build' 包含子文件夹中的所有脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!