【问题标题】:Manifest.json not copied to distManifest.json 未复制到 dist
【发布时间】:2018-06-21 20:09:19
【问题描述】:

我的 Angular 项目的目的是实现“添加到主屏幕”移动功能。在那个过程中,我选择了 manifest/PWA 方法,我在 index.html(根模板)的同一级别的项目的根文件夹中创建了 manifest.json,并在根模板(索引)的 head 部分添加了 manifest.json .html) 带有以下声明:. 但是在“ng build”时,我看到清单文件没有复制到 dist,因此在“dev tools->application->manifest”中单击“add to homescreen”时显示以下错误

Angular 正在开发模式下运行。调用 enableProdMode() 以启用生产模式。寻求帮助!

**localhost/:1 GET http://localhost:4200/src/manifest.json 404 (Not Found)
manifest.json:1 Manifest: Line: 1, column: 1, Unexpected token.**

以下是清单文件:

{
  "short_name": "Bus Express",
  "name": "BusEx",
  "start_url": "/",
  "background_color": "#ffffff",
  "display": "standalone",
  "scope": "/",
  "theme_color": "#fff",
  "icons": [
    {
      "src": "/assets/images/rateexpress128.png",
      "type": "image/png",
      "sizes": "128x128"
    },
    {
      "src": "/assets/images/rateexpress144.png",
      "type": "image/png",
      "sizes": "144x144"
    }
  ]
}

【问题讨论】:

  • 你手动添加了吗?
  • 是的,Pradeep。手动添加。当单击“开发工具/应用程序/清单”中的清单文件链接时,它包含以下内容:<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot GET /src/manifest.json</pre> </body> </html>

标签: angular pwa


【解决方案1】:

默认情况下文件不会复制到 dist 文件夹。您需要在 assets 选项、see here for an example.angular-cli.json 配置文件(如果 Angular 版本 see here for an example 的 angular.json 配置文件(如果 Angular 版本 >= 6)中手动添加它们.

【讨论】:

  • 非常感谢纪尧姆。现在它在 Angular.json 文件中添加 manifest.json 后得到修复,如下所示。 "assets": ["src/favicon.ico", "src/assets", "src/manifest.json"],但是我在angular 5的示例项目中尝试过这个改动,我的实际项目是angular1.5并且它不包含 angular-cli.json 或 angular.json 文件,那么我在我的 angular 1.5 项目中在哪里添加此更改?以及如何在 index.html 文件中保留 ,该文件当前在 gulp 构建后被删除。我们使用 gulp 构建。
【解决方案2】:

另外,我在内部将文件名更改为manifest.json,而angular.json 包含条目manifest.webmanifest...

【讨论】:

    【解决方案3】:

    go to angular.json

    add manifest.json location in assets

    "assets": [
                  "src/favicon.ico",
                  "src/assets",
                  "src/manifest.json"
              ],
    

    使用重启开发服务器 ng serve

    【讨论】:

      猜你喜欢
      • 2018-06-11
      • 1970-01-01
      • 2018-09-18
      • 2019-11-12
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 2015-11-16
      相关资源
      最近更新 更多