You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 17本地库导入:直接导入未构建库是否可行?

直接导入未构建的Angular Library是否可行?

我的目标是创建名为header和footer的Angular Library,供featureA、featureB等Angular应用导入使用。目前我计划通过相对路径直接导入未构建的库代码,导入方式如下:

import { HeaderComponent } from '../../../../../../../projects/header/src/public-api';

以下是项目中pass-data-between-components.page.ts的代码示例:

import { Component } from '@angular/core';
import { CheckoutSelectionComponent } from '../../components/checkout-selection/checkout-selection.component';
import { HeaderComponent } from '../../../../../../../projects/header/src/public-api';

@Component({
  selector: 'app-pass-data-between-components',
  standalone: true,
  imports: [
    CheckoutSelectionComponent,
    HeaderComponent,
  ],
  templateUrl: './pass-data-between-components.page.html',
  styleUrl: './pass-data-between-components.page.scss'
})
export class PassDataBetweenComponentsPage {
  constructor(
  ) {
  }
}

在Angular 17之前,我会先构建Angular Library,再导入库的dist文件——因为直接导入未构建的代码会增加编译负担。但Angular 17支持组件首次访问时才加载,所以我想尝试这种直接导入未构建库的方法。

我已经做过测试:执行npm run build后运行npm run serve:ssr:test-17,该方式可以正常工作。

请问直接导入未构建的Angular Library是否可行?


内容的提问来源于stack exchange,提问作者Jason Rich Darmawan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 02:10:18