mgechev / angular-seed

🌱 [Deprecated] Extensible, reliable, modular, PWA ready starter project for Angular (2 and beyond) with statically typed build and AoT compilation
https://mgechev.github.io/angular-seed
MIT License
4.57k stars 1.45k forks source link

Application decoupling #913

Closed mgechev closed 8 years ago

mgechev commented 8 years ago

Purpose

Allow easier development of multi-platform applications with easy code reuse across them.

Make the entire client-side application and its dependencies, decoupled from the build process and encapsulated inside src/client.

Background

At the moment we have our client application in the src/client directory and the build-related tasks in tools. Although we have this separation, all the client-side related dependencies and testing configuration are global (test-main.js, karma.config.js, protractor.config.js).

This makes it unpractical to use the seed for development of multiple Angular applications for different platforms which are sharing common features.

For instance, in case we want to develop backend for the current application, which reuses some of the logic which is already defined by services in the client-side, we need to:

This approach is not modular and has several drawbacks:

.
β”œβ”€β”€ appveyor.yml
β”œβ”€β”€ gulpfile.ts
β”œβ”€β”€ src
β”‚Β Β  └── client
β”‚       β”œβ”€β”€ dist
β”‚       β”œβ”€β”€ coverage
β”‚Β Β      β”œβ”€β”€ app
β”‚Β Β      β”œβ”€β”€ assets
β”‚Β Β      β”œβ”€β”€ css
β”‚Β Β      β”œβ”€β”€ index.html
β”‚       β”œβ”€β”€ test-main.js
β”‚Β Β      β”œβ”€β”€ tsconfig.json
β”‚       β”œβ”€β”€ karma.conf.js
β”‚       β”œβ”€β”€ package.json
β”‚       β”œβ”€β”€ protractor.conf.js
β”‚Β Β      └── typings.d.ts
β”œβ”€β”€ tools
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ tslint.json
β”œβ”€β”€ typings
β”œβ”€β”€ package.json
└── typings.json

@NathanWalker's advanced seed should benefit a lot from the proposal above.

// cc @ludohenin @d3viant0ne @TheDonDope @nareshbhatia

vyakymenko commented 8 years ago

@tarlepp , your tree it's a seed project, and folder's like client it's a branch(some first app with same dependencies), then you add another branch, folder fo example admin, and we have one tree with 2 branches.

But, I agree with your point !

For sometimes, tree can be.

vyakymenko commented 8 years ago

@tarlepp , I was thinking about your point that you told in latest comment and have some real-world example of this seed vision. One project --> One seed, it's a must for good project support. One project can have multi-applications, real example:

So, we will have 2 folders client, client-pay for example. And by the way, the client-pay can import, extend client(base) functionality, and we can add another feature for pay version. We can update client(free) core for 2 applications.

So we build one project(angular2-seed) with dual-application.

jerryorta-dev commented 8 years ago

Idea 1:
The SystemJS builder requires a config and the main.ts file. It recursively looks for all the imports, then using rollup and tree shaking to create the build. You can use this feature to have multiple app files -- mainTetrisFree.ts, mainTetrisPay.ts -- to create different builds. Each main file can import the proper feature set -- free or pay -- as needed and a gulp task wrapper to support each.

Idea 2:
SystemJS supports conditional loading. You can import the appropriate feature based on environment flags.

Idea 3: In conjunction with the ideas above, features can be shared via namespaced npm modules.

Any idea requires you to contend with the <%= SOME_VARIABLE %> variables.

jerryorta-dev commented 8 years ago

My fork now has an example of SystemJS Conditional Substitution feature -- loading/building and app to include featureA or featureB based on configuration. This is just a PoC to see how you can handle decoupling with SystemJS.