Angular 没有 index.html 的 CLI 构建
Angular CLI build without index.html
我们所有的 Angular 应用程序都在其他应用程序中引导(.jsp
文件加载 javascript 文件并包含 <app-root>
标记),因此我们不需要index.html
**.
但是,当我从 angular.json
中删除 index
属性 时,出现错误:
Data path "" should have required property 'index'.
如果我将其留空,它会生成,但出现错误:
...
95% emitting index-html-webpack-pluginEISDIR: illegal operation on a directory, read
Error: EISDIR: illegal operation on a directory, read
如何在没有 index.html
的情况下执行 ng build
?
** 我们的部署过程现在实际上将 index.html
复制到我们的 CDN,这是不需要的,因为我们根本不想将这些文件提供给最终用户,index.html
只是在 ng serve
期间供开发人员使用
您可以在 package.json
的 scripts
部分连接命令。所以附加一个删除命令并创建这样的东西(Windows命令;使其适应您的系统):
"scripts": {
"build prod": "ng build --prod --env=prod -op dist && del dist\index.html"
}
如果有人仍然遇到同样的问题,我就是这样解决的。
在你的angular.json
中:
"architect": {
"build": {
...
"configurations": {
"production": {
"index": "", // Do not copy index.html
...
ng build --prod
不会复制 HTML 文件,而 ng build
和 ng serve
将按预期继续使用它。
我们所有的 Angular 应用程序都在其他应用程序中引导(.jsp
文件加载 javascript 文件并包含 <app-root>
标记),因此我们不需要index.html
**.
但是,当我从 angular.json
中删除 index
属性 时,出现错误:
Data path "" should have required property 'index'.
如果我将其留空,它会生成,但出现错误:
...
95% emitting index-html-webpack-pluginEISDIR: illegal operation on a directory, read
Error: EISDIR: illegal operation on a directory, read
如何在没有 index.html
的情况下执行 ng build
?
** 我们的部署过程现在实际上将 index.html
复制到我们的 CDN,这是不需要的,因为我们根本不想将这些文件提供给最终用户,index.html
只是在 ng serve
您可以在 package.json
的 scripts
部分连接命令。所以附加一个删除命令并创建这样的东西(Windows命令;使其适应您的系统):
"scripts": {
"build prod": "ng build --prod --env=prod -op dist && del dist\index.html"
}
如果有人仍然遇到同样的问题,我就是这样解决的。
在你的angular.json
中:
"architect": {
"build": {
...
"configurations": {
"production": {
"index": "", // Do not copy index.html
...
ng build --prod
不会复制 HTML 文件,而 ng build
和 ng serve
将按预期继续使用它。