Which type of folder structure should be used with Angular 2?

后端 未结 9 1671
慢半拍i
慢半拍i 2021-01-29 18:45

I am an Angular 1 developer that is starting to learn about Angular 2. There are a lot of different types of folder structure methods depending on the training material. I am

相关标签:
9条回答
  • 2021-01-29 19:26

    So after doing more investigating I ended up going with a slightly revised version of Method 3 (mgechev/angular2-seed).

    I basically moved components to be a main level directory and then each feature will be inside of it.

    0 讨论(0)
  • 2021-01-29 19:26

    Maybe something like this structure:

    |-- app
         |-- modules
           |-- home
               |-- [+] components
               |-- pages
                  |-- home
                  |-- home.component.ts|html|scss|spec
               |-- home-routing.module.ts
               |-- home.module.ts
         |-- core
           |-- authentication
               |-- authentication.service.ts|spec.ts
           |-- footer
               |-- footer.component.ts|html|scss|spec.ts
           |-- guards
               |-- auth.guard.ts
               |-- no-auth-guard.ts
               |-- admin-guard.ts 
           |-- http
               |-- user
                   |-- user.service.ts|spec.ts
               |-- api.service.ts|spec.ts
           |-- interceptors
               |-- api-prefix.interceptor.ts
               |-- error-handler.interceptor.ts
               |-- http.token.interceptor.ts
           |-- mocks
               |-- user.mock.ts
           |-- services
               |-- srv1.service.ts|spec.ts
               |-- srv2.service.ts|spec.ts
           |-- header
               |-- header.component.ts|html|scss|spec.ts
           |-- core.module.ts
           |-- ensureModuleLoadedOnceGuard.ts
           |-- logger.service.ts
         |-- shared
              |-- components
                  |-- loader
                      |-- loader.component.ts|html|scss|spec.ts
              |-- buttons
                  |-- favorite-button
                      |-- favorite-button.component.ts|html|scss|spec.ts
                  |-- collapse-button
                      |-- collapse-button.component.ts|html|scss|spec.ts
              |-- directives
                  |-- auth.directive.ts|spec.ts
              |-- pipes
                  |-- capitalize.pipe.ts
                  |-- safe.pipe.ts
         |-- configs
             |-- app-settings.config.ts
             |-- dt-norwegian.config.ts
         |-- scss
              |-- [+] partials
              |-- _base.scss
              |-- styles.scss
         |-- assets
    
    0 讨论(0)
  • 2021-01-29 19:30

    I’ve been using ng cli lately, and it was really tough to find a good way to structure my code.

    The most efficient one I've seen so far comes from mrholek repository (https://github.com/mrholek/CoreUI-Angular).

    This folder structure allows you to keep your root project clean and structure your components, it avoids redundant (sometimes useless) naming convention of the official Style Guide.

    Also it’s, this structure is useful to group import when it’s needed and avoid having 30 lines of import for a single file.

    src
    |
    |___ app
    |
    |   |___ components/shared
    |   |   |___ header
    |   |
    |   |___ containers/layout
    |   |   |___ layout1
    |   |
    |   |___ directives
    |   |   |___ sidebar
    |   |
    |   |___ services
    |   |   |___ *user.service.ts* 
    |   | 
    |   |___ guards
    |   |   |___ *auth.guard.ts* 
    |   |
    |   |___ views
    |   |   |___ about  
    |   |
    |   |___ *app.component.ts*
    |   |
    |   |___ *app.module.ts*
    |   |
    |   |___ *app.routing.ts*
    |
    |___ assets
    |
    |___ environments
    |
    |___ img
    |   
    |___ scss
    |
    |___ *index.html*
    |
    |___ *main.ts*
    
    0 讨论(0)
提交回复
热议问题