对于 import {Injectable} from '@angular/core';
我想 package.json 的 module 属性指向导出 injectable
的文件?
对于格式 @angular/core/testing
,@angular/core
中是否有一个测试文件夹,其中包含另一个带有模块属性的 package.json
指向包含 testing
子模块导出的导出的文件?
最佳答案
你正在做某件事。查看@angular
模块的源代码,您确实会发现一个名为testing
的目录,它有自己的package.json
。
大多数 TypeScript
库使用 Barrel import/export
模式来“美化”您的导入路径。
path/to/nested/files/injectable.ts
export function Injectable() {
...
}
dist/index.js - 由 package.json
main
属性公开的文件。
export { Injectable } from 'path/to/nested/files/injectable.ts'
这将使您能够
import { Injectable } from '@angular/core'
而不是
import { Injectable } from '@angular/core/path/to/nested/files/injectable.ts'
通过分离模块,例如来自 testing
的 core
,您将从 Tree-Shaking
中受益,因为您只从库而不是整个包中导入所需的内容。
关于javascript - typescript如何解析@Angular/core/testing的导入以及Angular Core如何打包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44320241/