【问题标题】:Angular: Accessing assets of a libAngular:访问库的资产
【发布时间】:2022-11-24 16:42:18
【问题描述】:

我正在尝试从我的一个共享库访问一些资产,但不确定如何访问。

我的结构(nx 工作区)

/apps
-- my-app
   // ...

/libs
-- shared
   -- assets 
      -- resources
         -- translation.json

我的共享库定义了一个别名,例如:@my-company/shared

angular.json,我也定义了我的assets文件夹
shared.architect.build.options 中是这样的: "assets": ["./assets"]

现在我的问题是: 我想将翻译文件(通过带有 http 的相对路径)获取到我的应用程序中。我将如何引用它?

@my-company/shared/assets/resources/translation.json 之类的东西不起作用并返回 404。

【问题讨论】:

    标签: angular nrwl-nx nrwl


    【解决方案1】:

    在我的 Nx 项目中,我有 project.json,但我怀疑这在 angular.json 中也能正常工作。在 assets 选项下粘贴一个 glob 模式:

    {
      "name": "some-app",
      "$schema": "../../node_modules/nx/schemas/project-schema.json",
      "projectType": "application",
      "sourceRoot": "apps/some-app/src",
      "prefix": "my-org",
      "targets": {
        "build": {
          "executor": "@angular-devkit/build-angular:browser",
          "outputs": ["{options.outputPath}"],
          "options": {
            "outputPath": "dist/apps/some-app",
            "index": "apps/some-app/src/index.html",
            "main": "apps/some-app/src/main.ts",
            "polyfills": "apps/some-app/src/polyfills.ts",
            "tsConfig": "apps/some-app/tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "apps/login/src/favicon.ico",
              "apps/login/src/assets",
              {
                "input": "libs/shared/assets/src/lib", <------------ glob
                "glob": "**.*",
                "output": "assets"
              }
            ],
            "styles": ["apps/some-app/src/styles.scss"],
            "scripts": []
          },
          ...
    

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 2015-03-10
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2021-08-07
      • 2018-05-06
      相关资源
      最近更新 更多