00:01In this lecture we're gonna get familiar with webpac,
00:04which is in charge of packaging up elements
00:07inside of a website.
00:08It's a web packager, kind of the name implies,
00:11which we'll see a lot of it
00:12and you'll really get what it does throughout this title.
00:15We're also gonna install the webpac dev server
00:18that is an add-on to webpac that enables us
00:21to let it be used as our server for the usages
00:25of mainly a not real world server,
00:28but a server when you're doing testing.
00:30Now, if you're asking yourself why would you want
00:32to have a server, the answer is, is
00:33that if you mimic an environment of a server,
00:35even if you're only working on the client,
00:37you're creating an environment that is similar
00:39to real web applications, you really don't want
00:42to have two different complete environments
00:44and local host is the easiest way
00:46and we're gonna show you exactly how to do it.
00:48Once you do it once, it's gonna be incredibly easy.
00:50So let's just jump right into it
00:51and let's see, how can we use Webpack
00:53to create a local host server?
00:57Alright, so we're starting our project with an HTML file
01:01that has a headline, a paragraph,
01:03and a paragraph with a link in it.
01:06Also, you'll find besides that HT ML file,
01:09also find our package do JSON that we've created
01:13with the command NPM in it and just let it run
01:17and agreed to everything it asks us.
01:20The next thing that we wanna do is we wanna install a few
01:23packages, but we wanna install them not for just
01:27everyday usage, which is what normal packages are used for,
01:31but in this case, we want to load them up as a dependency
01:35that is only used while we package up our application.
01:40This is not a package that is gonna be used in development,
01:43but in in the production itself while the server is running,
01:46but it's only gonna be used while we're developing the
01:49server itself while we're building it up.
01:51And in this case we want to use Webpack.
01:53And Webpack is basically a library that enables us
01:56to package and compress and set up and configure things
02:00before the server starts running.
02:03It's basically a task runner for web packaging.
02:06The next thing that we want to install O2 is web pack
02:11dev server that works with webpac
02:14and enables us to run a server while our
02:19while running on a client.
02:20And it's a very, very fantastic
02:22solution in which you're gonna get
02:23to discover really well throughout the next few sessions.
02:27So with that said, let's go ahead and click on enter.
02:29And what's gonna happen is NPM is gonna go
02:31and fetch web pack, web pack, dev server,
02:35and any other package that it might need.
02:37Now it's gonna take all those packages
02:39and they're gonna, it's gonna be placed inside of a folder
02:42inside of our structure, which is called node modules
02:45because these are node modules.
02:48And as the process continues, it will go ahead
02:50and add all the different packages that it needs
02:53for it to actually work.
02:54And you can see that quite a lot
02:56of packages have been installed automatically
02:59Beyond that. Also,
03:00because we set our configuration
03:02with the dash save dash dev, what actually happened,
03:05and I actually have your small mistake,
03:07but let's see if it actually saved it the way we
03:10would want it to be saved.
03:11It did so even though I, I was supposed
03:13to put two dashes there, um,
03:15although that's what the documentation says,
03:17it actually was forgiving enough to understand that we meant
03:20that we meant, um, the save dev.
03:23So usually you're supposed to be two dashes there,
03:25but also one dash seemed to have worked
03:27and what happened is it said saved it into our dev
03:30dependencies, which basically means that webpac
03:34and Webpac dev server will be available
03:36as we're packaging up
03:38and starting up our server, the next step that I want
03:41to do is set up and configure webpac
03:44and the Webpack dev server.
03:46Now the best way to do that is through another file,
03:49which is gonna be A-J-S-O-N file
03:51or a JavaScript file actually more accurately.
03:54And that JavaScript file,
03:55and let me just go ahead into our terminal needs
03:58to be called touch webpac
04:03config js.
04:04So I'm creating that file and let's go ahead
04:06and create the basic construct inside
04:08of there that it's expecting.
04:10So first of all, inside of our web pack,
04:12which is gonna sit in the same directory
04:13as our package JS O.
04:16So what we need to do next is literally, this is a standard
04:20to really know js, which is derived out of create js.
04:24But what we wanna do is we wanna define a
04:26module, do exports.
04:28And this is true to really any module really.
04:30And this is a module.
04:31We're not gonna get into the terminologies of no JS
04:35because it's just, we're gonna fly through it
04:37as our focus is gonna be mainly on the client,
04:40although we're gonna be using a lot of things in NPM itself.
04:43So web back itself expects us this structure
04:46that it's gonna basically have gain access
04:48to from this JSON file.
04:50Oh, sorry, this JavaScript file, not JSO file.
04:53Now what I'm gonna do is I'm gonna define here our dev
04:56server, and I'm literally just gonna put here a few
04:59configurations that will make our coding so much easier.
05:03And the first one is inline, which is we're gonna set it
05:06to true, which what is not online,
05:08although it's very similar in line.
05:09What that's gonna do is it's gonna make sure
05:12that anytime we make any changes in our code,
05:15our server will reconfigure itself
05:18and refresh itself in the browser itself as well.
05:21Really incredible stuff.
05:23The next stuff, and by the way,
05:24it's not gonna work immediately,
05:25it's only gonna work once we have some JavaScript
05:28included into our content.
05:30The next thing is our content base
05:32and our content base will tell our server
05:34that we're creating where is the actual starting folder.
05:38And in our case, we want our starting folder
05:40to be our public folder where our HTML file is located.
05:44Last but not least, we don't want to use the default port
05:47because something else might be using it.
05:49And I'm gonna go ahead and just say here, 3000,
05:52although you could use any value,
05:53especially if you run the server
05:55and it doesn't actually work in the end.
05:58So the next thing that you wanna do once you saved
06:00and configured this is to go into and start up your server.
06:05Now you could do it directly through terminal,
06:08but the process itself is quite convoluted
06:11and comple complex
06:12because you would have to find the node module,
06:15the web pack dev server and inside of it, the bin folder
06:19and inside of it that web pack dev server
06:21and start it up from there.
06:23But that is a lot of typing to do and the easiest
06:26and most accessible way to do that is to go into your JSO,
06:30your package, do JSON, which is your project file,
06:33and go and add a script.
06:34In this case, we don't have any testing,
06:37so I'm just gonna replace the testing with start
06:40and let me just go ahead here
06:41and delete the value that was there.
06:43And instead of that, just call our web pack dev server
06:48and that's literally all we have to do.
06:50I'm gonna save that to be able to gain access to a script.
06:53And you could use many scripts
06:54that way if you encounter a situation when you need them.
06:58All that's left for us to do is to go to the terminal
07:02and in term, terminal type NPM Run
07:05and the name of the script, in our case,
07:07we call it start now
07:09because start is such a common thing,
07:11you don't even have to type run.
07:13You could just type NPM start and we will go ahead
07:16and start up our server, but we have a error here
07:19and I don't see exactly what the error is,
07:24so I know what it is be
07:27because really what Webpack does,
07:28it mainly packages JavaScript files.
07:32And because we don't really have any JavaScript file, so we,
07:35we we, it's trying to package
07:37and put some JavaScript into nowhere.
07:38So it's throwing an error.
07:40Let me just go ahead and comment that inline value.
07:43We will undo that once we have some JavaScript in our file.
07:46And if we go back and try to run it one more time,
07:49we should now have NPM start up
07:52and our server should start up.
07:54So now that our server is running,
07:56we could go ahead into our web host
07:58and hopefully it will show us our website.
08:02Beautiful. And it does in this lecture,
08:07we created a local host server with the help of webpac.
08:10In the next lecture, we'll move back
08:12to building out our visuals as we bootstrap our HTML,
08:16adding into it some bootstrap components.