How can I organize my Angular app folders like a Java package?
如何组织Angular 2应用程序文件夹结构(如Java包)?
考虑以下项目布局:
1 2 3 4 | app |_model |_component |_service |
我想将
有没有办法像Java包一样从根文件夹引用具有绝对浴池的文件夹?
更新2016-06-01
使用
我假设你的树看起来像这样:
1 2 3 4 5 6 7 8 9 | node_modules |_@angular |_rxjs app |_model |_component |_service package.json tsconfig.json |
您应该在tsconfig.json中添加以下几行:
1 2 3 4 5 6 7 8 9 10 11 | { "compilerOptions": { "baseUrl":".", "paths": { "*": [ "app/*", "node_modules/*" ] } } } |
那么您可以像使用常规@ angular / rxjs模块一样引用您的模块
1 2 3 | import { MyService } from 'service/MyService'; import { Component } from '@angular/core'; import { Observable } from 'rxjs'; |
注意:webpack在webpack.config.js中还需要以下几行
1 2 3 4 5 6 | resolve: { modulesDirectories: [ 'node_modules', 'app' ] } |
尚未,TypeScript 2.0应该很快会出现
看这里
https://github.com/Microsoft/TypeScript/issues/5039