【问题标题】:Read Json file inside Angular custom library在 Angular 自定义库中读取 Json 文件
【发布时间】:2021-01-31 23:56:14
【问题描述】:

我正在尝试在 Angular 8 中构建自定义库。我正在尝试从 Angular 库工作文件中的 JSON 文件读取数据,但是当我构建库并在项目中使用时,JSON 文件路径不正确。

当我在项目中使用这个库时,出现如下错误

./node_modules/chatbot-lib/fesm2015/chatbot-lib.js 中的错误 找不到模块:错误:无法解析“D:\demo\DemoApplication\XmppConnection\node_modules\chatbot-lib\fesm2015”中的“projects/chatbot-lib/src/assets/Loc.json”

另外,有人可以帮我在 Angular 库中添加全局 SCSS 吗?

【问题讨论】:

    标签: javascript angular angular-material angular-library


    【解决方案1】:

    您的项目看起来像一个 monorepo。如果是,请尝试在 compilerOptions.paths 中为 tsconfig 指定外部路径别名

    {
      compilerOptions: {
        ...
        paths: {
          "@chatbot": ["projects/chatbot-lib/index.ts"], // <RELATIVE_PATH>
          "@chatbot/assets": ["projects/chatbot-lib/src/assets/index.ts"]
        }
      }
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-05
      • 2017-04-02
      • 1970-01-01
      • 2018-02-11
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      相关资源
      最近更新 更多