How can I organize my Angular app folders like a Java package?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 14:14:18

UPDATE 2016-06-01

using npm install typescript@next you can already use this function

I assume that your tree looks like this:

node_modules
 |_@angular
 |_rxjs
app
 |_model
 |_component
 |_service
package.json
tsconfig.json

You should add in your tsconfig.json the following lines:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "*": [
        "app/*",
        "node_modules/*"
      ]
    }
  }
}

then you can reference your modules like you do with regular @angular/rxjs modules

import { MyService } from 'service/MyService';
import { Component } from '@angular/core';
import { Observable } from 'rxjs';

Note: webpack needs also the following lines in webpack.config.js

resolve: {
    modulesDirectories: [
        'node_modules',
        'app'
    ]
}

Not yet, it should be present soon with Typescript 2.0

Look here https://github.com/Microsoft/TypeScript/issues/5039

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!