Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,090 --> 00:00:04,370
Now before we get our hands dirty,
2
00:00:04,370 --> 00:00:07,260
let's understand deployment in theory.
3
00:00:07,260 --> 00:00:10,420
And let's start with the different deployment options
4
00:00:10,420 --> 00:00:12,670
Next.js gives you.
5
00:00:12,670 --> 00:00:14,340
Because it turns out,
6
00:00:14,340 --> 00:00:17,990
that you have two totally different ways of building
7
00:00:17,990 --> 00:00:21,120
and deploying your Next.js app.
8
00:00:21,120 --> 00:00:25,700
The first and most common option is the Standard Build,
9
00:00:25,700 --> 00:00:27,810
as I like to call it.
10
00:00:27,810 --> 00:00:31,950
But we also can actually do a Full Static Build
11
00:00:31,950 --> 00:00:36,670
and deploy our site as a full static website.
12
00:00:36,670 --> 00:00:39,253
Now, let me explain what these two options mean.
13
00:00:40,160 --> 00:00:44,730
You do a standard build by running the next build command
14
00:00:44,730 --> 00:00:49,090
or in your project, where you have a package.json file,
15
00:00:49,090 --> 00:00:53,970
this build script which runs next build under the hood.
16
00:00:53,970 --> 00:00:56,810
We saw that command in action earlier
17
00:00:56,810 --> 00:00:58,180
in the course already,
18
00:00:58,180 --> 00:01:02,010
when we talked about static page generation and so on.
19
00:01:02,010 --> 00:01:04,230
When running this command,
20
00:01:04,230 --> 00:01:09,100
Next.js produces a optimized production build,
21
00:01:09,100 --> 00:01:12,760
optimized production bundles for your application
22
00:01:12,760 --> 00:01:17,760
and very important, it spits out a service-side application.
23
00:01:18,410 --> 00:01:21,130
The result of running next build
24
00:01:21,130 --> 00:01:26,130
is an output that requires a NodeJS server to run it.
25
00:01:27,170 --> 00:01:31,050
So you can't take the output of next build
26
00:01:31,050 --> 00:01:34,070
and put it onto some static host.
27
00:01:34,070 --> 00:01:38,280
You would be able to do that for a standard React app,
28
00:01:38,280 --> 00:01:42,650
a non Next.js app, but because Next.js
29
00:01:42,650 --> 00:01:46,180
has these built-in service-side capabilities,
30
00:01:46,180 --> 00:01:49,950
like pre-rendering pages on the fly, on the server,
31
00:01:49,950 --> 00:01:52,930
revalidating pages, API routes.
32
00:01:52,930 --> 00:01:55,870
Because it has these service-side features,
33
00:01:55,870 --> 00:02:00,210
it needs a NodeJS server to run that code,
34
00:02:00,210 --> 00:02:01,420
should make sense.
35
00:02:01,420 --> 00:02:02,970
Now don't get me wrong,
36
00:02:02,970 --> 00:02:05,380
pages will still be pre-rendered
37
00:02:05,380 --> 00:02:08,120
during the build process if possible.
38
00:02:08,120 --> 00:02:11,970
So if you have pages with get static props
39
00:02:11,970 --> 00:02:14,050
or with no data at all,
40
00:02:14,050 --> 00:02:18,970
those pages will still be prebuilt when you run next build.
41
00:02:18,970 --> 00:02:22,740
But you still have the NodeJS server, as I just explained,
42
00:02:22,740 --> 00:02:24,560
for your API routes,
43
00:02:24,560 --> 00:02:27,623
which can and should only run on the server,
44
00:02:27,623 --> 00:02:29,510
for server-side pages
45
00:02:29,510 --> 00:02:33,010
that use the get server-side props function
46
00:02:33,010 --> 00:02:35,770
and for page revalidations,
47
00:02:35,770 --> 00:02:37,360
which you might wanna perform
48
00:02:37,360 --> 00:02:40,810
on your statically rendered pages.
49
00:02:40,810 --> 00:02:45,769
You also need a NodeJS server for dynamic pages
50
00:02:45,769 --> 00:02:50,440
with getStaticPaths if you have fallback set to true
51
00:02:50,440 --> 00:02:55,440
or blocking, because then some of the pages will be created
52
00:02:55,450 --> 00:02:59,340
on the fly when requests are reaching the server.
53
00:02:59,340 --> 00:03:02,020
And you need a server that is able to do that
54
00:03:02,020 --> 00:03:03,600
for that as well.
55
00:03:03,600 --> 00:03:07,020
So that is why you need a NodeJS server
56
00:03:07,020 --> 00:03:11,270
for running the output next build gives you.
57
00:03:11,270 --> 00:03:13,090
And that has implications.
58
00:03:13,090 --> 00:03:16,080
It means that when you deploy that output,
59
00:03:16,080 --> 00:03:18,910
you need to deploy it onto a host
60
00:03:18,910 --> 00:03:21,730
that is able to run NodeJS.
61
00:03:21,730 --> 00:03:25,400
And we're going to see that later in this course section.
62
00:03:25,400 --> 00:03:29,050
Now when deploying a site, an application
63
00:03:29,050 --> 00:03:33,730
you also typically need to redeploy from time to time.
64
00:03:33,730 --> 00:03:35,780
And when doing a standard build,
65
00:03:35,780 --> 00:03:39,870
you need to redeploy whenever your code changes, of course
66
00:03:39,870 --> 00:03:42,210
because you want your latest code to be
67
00:03:42,210 --> 00:03:44,600
in effect in production,
68
00:03:44,600 --> 00:03:48,700
but you will also need to redeploy if your content changed
69
00:03:48,700 --> 00:03:52,820
and you need to re-render some of your pages
70
00:03:52,820 --> 00:03:56,700
because you're not revalidating them on the server
71
00:03:56,700 --> 00:04:00,560
because you haven't added that revalidate setting
72
00:04:00,560 --> 00:04:02,340
in get static props.
73
00:04:02,340 --> 00:04:04,540
Then if you have such pages
74
00:04:04,540 --> 00:04:09,220
as we, for example have them in our blog application here
75
00:04:09,220 --> 00:04:12,550
in our blog site, there I have pages
76
00:04:12,550 --> 00:04:16,079
where I pre-rendered the pages with some data
77
00:04:16,079 --> 00:04:18,329
and I don't revalidate.
78
00:04:18,329 --> 00:04:20,970
If you have such pages, which is no problem,
79
00:04:20,970 --> 00:04:22,700
but if you have such pages,
80
00:04:22,700 --> 00:04:25,040
you will also need to redeploy
81
00:04:25,040 --> 00:04:28,580
whenever the contents that influences those pages
82
00:04:28,580 --> 00:04:32,680
or that impacts those pages changed.
83
00:04:32,680 --> 00:04:34,300
Now that's the standard build,
84
00:04:34,300 --> 00:04:36,530
which you get with next build.
85
00:04:36,530 --> 00:04:38,400
For some projects,
86
00:04:38,400 --> 00:04:41,670
the full static build is a good option though.
87
00:04:41,670 --> 00:04:45,953
You get that by running next export, another command.
88
00:04:46,870 --> 00:04:49,110
We could run this in our project
89
00:04:49,110 --> 00:04:51,630
by adding a script for that.
90
00:04:51,630 --> 00:04:53,160
Here in package.json,
91
00:04:53,160 --> 00:04:55,330
we could add a export script
92
00:04:55,330 --> 00:04:57,020
or a however you wanna call it,
93
00:04:57,020 --> 00:04:59,363
where we then run next export.
94
00:05:01,010 --> 00:05:04,480
Now next export does something totally different
95
00:05:04,480 --> 00:05:06,130
than next build.
96
00:05:06,130 --> 00:05:09,940
It also produces an optimized production version
97
00:05:09,940 --> 00:05:11,350
of your application
98
00:05:11,350 --> 00:05:16,120
but it produces a 100% static application,
99
00:05:16,120 --> 00:05:20,500
which means only HTML, CSS and JavaScript,
100
00:05:20,500 --> 00:05:22,280
no server-side code
101
00:05:22,280 --> 00:05:25,490
and therefore for hosting such a website,
102
00:05:25,490 --> 00:05:28,480
you don't need a NodeJS server.
103
00:05:28,480 --> 00:05:31,950
Which makes hosting easier because you don't need to worry
104
00:05:31,950 --> 00:05:34,370
about scaling and so on, so much
105
00:05:34,370 --> 00:05:37,520
because there are plenty of static hosts out there
106
00:05:37,520 --> 00:05:41,720
which scale dynamically and are very cost-effective.
107
00:05:41,720 --> 00:05:43,190
So having a static app,
108
00:05:43,190 --> 00:05:47,150
which doesn't require a NodeJS server, isn't too bad.
109
00:05:47,150 --> 00:05:50,630
It can definitely make deployment a bit easier
110
00:05:50,630 --> 00:05:54,330
but next export isn't always an option.
111
00:05:54,330 --> 00:05:58,010
Since it spits out a 100% steady gap,
112
00:05:58,010 --> 00:06:01,330
there are certain things, certain next features
113
00:06:01,330 --> 00:06:04,740
which you just can't use in such a application.
114
00:06:04,740 --> 00:06:07,690
For example, you can't use next export
115
00:06:07,690 --> 00:06:11,020
if your site relies on API routes,
116
00:06:11,020 --> 00:06:14,850
on service-side pages with get service-side props,
117
00:06:14,850 --> 00:06:16,970
on page revalidations,
118
00:06:16,970 --> 00:06:20,880
or if you have static paths with fallback set to true
119
00:06:20,880 --> 00:06:22,330
or blocking.
120
00:06:22,330 --> 00:06:27,180
All those things require a code to execute on demand,
121
00:06:27,180 --> 00:06:30,440
for incoming requests on the server.
122
00:06:30,440 --> 00:06:33,600
And therefore it's difficult, if you have no server.
123
00:06:33,600 --> 00:06:35,880
So next export only works
124
00:06:35,880 --> 00:06:39,773
if you have a page which doesn't need any service-side code.
125
00:06:40,630 --> 00:06:44,240
Now, when building a page with next export,
126
00:06:44,240 --> 00:06:46,830
you have to be aware of the fact that
127
00:06:46,830 --> 00:06:51,290
that means that you need to redeploy your application
128
00:06:51,290 --> 00:06:53,290
whenever your code changes
129
00:06:53,290 --> 00:06:56,630
but also whenever any content changes,
130
00:06:56,630 --> 00:06:59,740
since you can't use page revalidations
131
00:06:59,740 --> 00:07:01,490
and fallbacks and so on,
132
00:07:01,490 --> 00:07:05,540
you need to redeploy whenever any content changed
133
00:07:05,540 --> 00:07:08,840
because you'll need to export your application again.
134
00:07:08,840 --> 00:07:11,830
You need to rebuild all the pages again.
135
00:07:11,830 --> 00:07:14,480
Again, that might not be a disadvantage.
136
00:07:14,480 --> 00:07:18,770
That can be perfectly fine for a simple blog, for example.
137
00:07:18,770 --> 00:07:21,540
There you add a new blog post every week,
138
00:07:21,540 --> 00:07:23,880
you do a redeployment every week.
139
00:07:23,880 --> 00:07:26,740
Not too difficult, just one step,
140
00:07:26,740 --> 00:07:30,100
and then next export can be a great option.
141
00:07:30,100 --> 00:07:34,010
In the blog application we built in the last course section,
142
00:07:34,010 --> 00:07:36,940
next export wouldn't be our option at the moment
143
00:07:36,940 --> 00:07:40,220
because we're using API routes, for example
144
00:07:40,220 --> 00:07:44,670
and because we're also using revalidations in some pages
145
00:07:44,670 --> 00:07:49,030
and these are all features that require a NodeJS server,
146
00:07:49,030 --> 00:07:50,560
since these are all tasks
147
00:07:50,560 --> 00:07:53,300
which will execute after deployment
148
00:07:53,300 --> 00:07:56,210
on the server for incoming requests.
149
00:07:56,210 --> 00:07:58,700
Nonetheless, these are your two options
150
00:07:58,700 --> 00:08:00,210
and we are going to see
151
00:08:00,210 --> 00:08:03,523
both options in action in this course section.
11898
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.