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

后端 未结 2 1613
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 01:15

How to organize Angular 2 app folder structure like Java packages?

Consider the following project layout:

app
 |_model
 |_component
 |_service


        
相关标签:
2条回答
  • 2021-01-03 01:24

    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'
        ]
    }
    
    0 讨论(0)
  • 2021-01-03 01:28

    Not yet, it should be present soon with Typescript 2.0

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

    0 讨论(0)
提交回复
热议问题