I'm working on an angular application. We based our application on https://github.com/Swiip/generator-gulp-angular and everything is working fine. This angular seed project basically scans all your JS files in a directory and concats them into a single JS file when you go into production.
We're building an admin backend for a billing system. The client now also wants a "public backend" for all their clients. A place where clients and log in and send messages basically. The UI is the same for the public backend, we could re-use the same directives everywhere. The only problem is that the public backend is tiny and the admin backend is huge. I don't think serving the full admin app to a random client is good practice.
How do I go about building two applications from the same code base?
So now, you need to follow some simple steps to use multiple modules in an Angular application. Create a simple application using Angular CLI. If you are going to use Angular for the first time, click here. I am going to create an application which contains three modules: App, Employee, Admin, Home.
AngularJS applications cannot be nested within each other. Do not use a directive that uses transclusion on the same element as ngApp . This includes directives such as ngIf , ngInclude and ngView .
The Angular Multi-Platform Starter is a template for building apps that run across the web, native mobile (using NativeScript), and for desktop (using Electron). Angular 2 decoupled the Angular framework from the DOM, making the promise of a single code base that runs across multiple environments a real possibility.
Don't serve two applications from the same codebase. That is a recipe for disaster. This is a rough outline of how I would handle this:
As noted by others, you would manage the apps with a good build tool like Grunt/Gulp which would pull in the common dependencies for you.
I'd have to disagree with the accepted answer as well. Maintaining one codebase is significantly more straightforward and less time consuming, and will be favorable in case where your project expands into even bigger number of applications that need to be deployed and built independently.
Defining the build
There would be one app.js file per application, defining which components to import and make the build from. The structure could look similar to the following:
components
-- component-1
-- component-2
-- component-3
app-1
-- app.js
app-2
-- app.js
To build app-1, we need components 1 and 3, so in app-1/app.js we'd define:
require('../components/component-1/file.js')
require('../components/component-3/file.js')
If you'd want to deploy separately user-related settings, you could create UserSettings module, with its own routes, and include components this module needs. This module would then be included in the build of your application. The same could apply to routes, config, runs etc. - optimally these would all pertain to one module, or component.
Dependencies
At some point you'll face the question of whether you want to bundle dependencies for all applications in one go, or create a bundle for each application separately. The only solution I came up with so far, is to curate manual list of dependencies for each application, and execute a bundler based on that list, but I'm sure there's a better way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With