Modular folder structure


#1

I am wondering if it is possible to create modular folder structure in ionic 2 without any problems.
Currently my app uses the default
app/
pages/
providers/

structure.

However, I’d like to organize functional modules as such to be able to reuse them in another app easily (and since I prefer functional modules over type-folders since its a lot more manageable).

So the structure I have in mind would be more like
/app
/modules
|-- feature 1
…|-- subfeature 1.1
…|-- subfeature1.1.html
…|-- subfeature1.1.ts
…|-- subfeature1.1.service.ts
|-- feature 2

am I limited to use the “pages” and “providers” folder? is the compiler somehow using this specifically?

Thanks for your response.

Maybe it would be a good idea to make such feature-based modular structure the default ionic structure since its quite better to handle?

edit:
Bonus question:
Can I somehow create a @NgModule for each feature and subfeature and get any advantage from it? e.g. Could I maybe register declarations, entryComponents, providers etc. within each module and only provide such module to the main App module, so that the main app does not have to include each single page, provider etc.?


#2

Based on my tests you can use whatever structure you like.

I also prefer to follow the Angular Style Guide for the project structure and file naming. However the Ionic team seem to have different preferences.


#3

Thanks I will have a closer look at this conventions!
What about the ngModule question, any experience yet?


#4

I haven’t tried multiple modules yet, but I guess that should work as well.


#5

I tried it with multiple modules and it works, but I have to import IonicModule into each feature module that uses ionic 2 directives or components. The problem I see with this you can find in these threads: Modular App Structure with Ionic 2
Best practice for app.module in Ionic 2 RC0.