Fireship · @fireship
Big JavaScript Projects - Code Sharing
Uploaded September 6, 2018 · Length 8:01
Summary
Sharing code between large JavaScript projects using Firebase and NPM, including creating a shared library and setting up multiple hosting targets.
- javascript code sharing
- firebase hosting
- npm packages
- shared libraries
- mono repos
- multi repos
- javascript project structure
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:06
code reusability is one of the most
- 0:08
important concepts in all of software
- 0:10
development but what often happens is
- 0:12
you write some code in one app and then
- 0:13
you want to reuse it in a different app
- 0:15
down the road maybe you're back at cloud
- 0:17
functions or a different front-end app
- 0:18
but it's not very easy to reuse that
- 0:21
code because it's tightly coupled to one
- 0:22
specific app in today's video we'll look
- 0:24
at code sharing strategies specifically
- 0:27
for large JavaScript projects if you're
- 0:29
new the channel like and subscribe and
- 0:31
grab the full source code from angular
- 0:33
firebase.com and i'm also giving away
- 0:35
some free swag with this video all you
- 0:37
have to do is leave a comment below and
- 0:38
I'll randomly pick a winner by this
- 0:40
weekend let's imagine that we have three
- 0:42
different apps we have a customer facing
- 0:44
angular app we used view to build an
- 0:46
admin app and then we have a cloud
- 0:47
functions back-end with note j s our
- 0:50
goal with this video is to orchestrate
- 0:52
all these projects with firebase and
- 0:54
then also share common business logic
- 0:56
and typescript interfaces between them
- 0:58
so I just have an empty directory opened
- 1:01
up here in vs code and the first thing
- 1:02
I'll do is generate our angular
- 1:04
front-end by running the ng new command
- 1:06
this just generates a basic angular app
- 1:08
but the important thing to keep in mind
- 1:10
here is that this project has its own
- 1:12
package.json and it also has its own
- 1:14
dedicated git repository now to add some
- 1:17
complexity I'll also generate a view app
- 1:20
with the view CLI and just like angular
- 1:22
it has its own package JSON and its own
- 1:24
git repo then we'll give our app a
- 1:26
back-end by initializing firebase and
- 1:28
I'm going to select functions and
- 1:30
hosting as the firebase features the
- 1:33
functions directory is also a node.js
- 1:34
project so it has its own package JSON
- 1:37
and then it doesn't have a git
- 1:38
repository by default but you can
- 1:39
initialize one in there as well so now
- 1:42
we have firebase initialized in this
- 1:44
parent directory and we can orchestrate
- 1:45
the deployments for our front-end apps
- 1:47
and our functions I have an entire video
- 1:50
on multi site hosting so make sure to
- 1:51
check that out but what we can do in
- 1:53
this firebase JSON file is set up
- 1:55
multiple hosting targets so we can
- 1:57
deploy our angular app to one URL and
- 1:59
our view app to a different URL but have


