【问题标题】:How to include assets from node_modules in angular cli project如何在 Angular cli 项目中包含来自 node_modules 的资产
【发布时间】:2017-05-24 03:54:50
【问题描述】:

如何将外部库中的资产包含到 Angular CLI 项目中

我在下面尝试,但这不起作用,

  "assets": [
    "../node_modules/<external library>/assets/"
  ]

脚本运行良好,

 "scripts": [  
    "../node_modules/<external library>/some.js",     
    "startup.js"
 ]

角度版本:2.4.1

Angular CLI:1.0.0-beta.24

有什么建议吗?

【问题讨论】:

  • 尝试删除assets之后的最后一个/
  • 上次删除 /,不起作用
  • 尝试“资产”:[“../node_modules//assets/*”]

标签: angular angular-cli


【解决方案1】:

我是新来的,但我遇到了 npm 包的问题,​​就像在我的情况下,我必须通过当前应用程序中的 npm 包和包本身的图像调用另一个应用程序 UI。

我们需要这个案例的 2 处更改:

  • Angular 6 在相应的 ng-package json 中添加:assets:['./assets'] 在子应用程序中,因为这将在构建时在 dist 文件夹中创建 assets/image 文件夹。

  • 在 angular.json 中添加(在架构师和测试中)父应用程序:

assets: [
   {
      "glob": "**/*",
      "input":"node_modules/"path of assets folder"/images"
   },
   "output":"./assets/images/"
]

【讨论】:

    【解决方案2】:

    不幸的是,这还不存在 :(。我也在拼命等待这个功能。请随时在此处跟踪 Angular-Cli 的此功能请求。Copying assets from node_modules

    更新

    参见 @luvaas Angular 6 的响应!

    【讨论】:

      【解决方案3】:

      自 Angular 6 以来,配置略有变化。现在要实现这一点,请更改angular.json 中相应构建器的assets 属性(注意,架构师buildtest 中至少有两个相关构建器!)

      "assets": [
        "src/favicon.ico",
        "src/assets",
        {
          "glob": "**/*",
          "input": "./node_modules/<your-node-module>/<possibly-subfolders>",
          "output": "./assets/<possibly-subfolders>"
        },
      

      【讨论】:

        【解决方案4】:

        现在确实存在!

        Fix #3555

        要使用它,请像这样更新您的 .angular-cli.json 文件...

        Angular 版本 2-5:

        "assets": [
          "assets",
          { "glob": "**/*", "input": "../node_modules/<external library>/assets/", "output": "./assets/" }
        ]
        

        角度版本 >= 6:

        "assets": [
          "src/favicon.ico",
          "src/assets",
          {
            "glob": "**/*",
            "input": "./node_modules/<your-node-module>/<possibly-subfolders>/",
            "output": "./assets/"
          },
        

        【讨论】:

        • 不幸的是,这对于 angular 6 不再起作用。对于 angular 6 配置,请参阅下面的答案。
        • 我不得不改变:“输入”:“../node_modules//...”到“输入”:“./node_modules//...”node_modules与 angular.json 中的同一级别
        • 让它也适用于“ng serve”的最佳方式是什么?我知道你可以在本地添加一个符号链接,这样文件看起来就在 assets 文件夹中 - 还有其他方法吗?
        • 在 Angular 6 之前的版本中,此方法应该适用于“ng build”和“ng serve”。他们都使用 .angular-cli.json。
        猜你喜欢
        • 2019-03-04
        • 2023-03-09
        • 1970-01-01
        • 2017-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-19
        • 2017-01-02
        相关资源
        最近更新 更多