Getting Started with Webpack 5 in 2021

Поділитися
Вставка
  • Опубліковано 15 вер 2024
  • This tutorial walks you through everything you need to get started using Webpack in your projects. If you are doing React development it will also help you to understand the role that Webpack plays in that too.
    The core concepts of Entry points, Output configuration, Loaders, Plugins, Development web servers, and hot reloading are all discussed in detail, PLUS some of the key improvements that Webpack 5 has over Webpack 4.
    Code from video:
    gist.github.co...
    Webpack core concepts:
    webpack.js.org...
    Webpack official Guides:
    webpack.js.org...
    Webpack official Configuration settings and options:
    webpack.js.org...

КОМЕНТАРІ • 162

  • @alexandershcheglov4653
    @alexandershcheglov4653 2 роки тому +35

    Just for ones who new here. There is "static" instead "contentBase" since last update I think. Thank you for the great explanation. You have a new subscriber now.

    • @ryanmcpherson6167
      @ryanmcpherson6167 2 роки тому +3

      Huge help! Thanks!

    • @marcinkalmar9964
      @marcinkalmar9964 2 роки тому +1

      thanks mate , your comment give my direction toward solve my problem :)

    • @ranguy1379
      @ranguy1379 Рік тому

      Also watchContentBase isn't necessary anymore, it's already enabled by default

  • @katkodes6055
    @katkodes6055 Рік тому +4

    Steve, I was on the verge of tears with webpack and you fixed it. I know this took time and effort to make so I thank you for it!

  • @keithhuels4178
    @keithhuels4178 2 роки тому +9

    Probably the best single tutorial video I've seen. From your pacing, to barebones explanations of WHY each line is needed, to your calming voice. Superb. I came here after webpack's official docs and they should hire you lol.

    • @omersoncruz1081
      @omersoncruz1081 Рік тому

      I agree with the calming voice. Love it specially when you're dealing with this kind of source of headache lol

  • @pashabiceps95
    @pashabiceps95 3 місяці тому

    The best tutorial for actually understanding

  • @alexmutschlechner8205
    @alexmutschlechner8205 Рік тому +1

    The best tutorial that i have found.

  • @vonwieckvonwieck
    @vonwieckvonwieck Рік тому +1

    Hi Steve, special Thanks you save me alot of time. This was exactly what i am looking for. Very Good example for a beginner tutorial. With best regards from Germany

  • @wiktorliszkiewicz354
    @wiktorliszkiewicz354 2 роки тому +8

    Update:
    In webpack.config.js:
    devServer:{
    static: path.resolve(__dirname, 'dist'),
    port: 5001,
    open: true,
    hot: true,
    }
    and in package.json:
    "dev": "webpack serve --mode development ",
    "build": "webpack --mode production"

  • @bartek4210
    @bartek4210 2 роки тому +16

    Great tutorial, very well explained and I like the slow pace.
    In the newer version of the "webpack-dev-server" the "contentBase" have to be replaced with "static" and "watchContentBase" gives errors so I just removed it, and to make hot realoding work replace "dist" with "src" in the "static: path.resolve(__dirname, 'src'),"
    ```
    devServer: {
    static: path.resolve(__dirname, 'src'),
    port: 5001,
    open: true,
    hot: true,
    },
    ```

  • @kube-tech7384
    @kube-tech7384 2 роки тому

    from the deepest of my heart "THANK YOU "

  • @elbekxatanboyev4584
    @elbekxatanboyev4584 2 роки тому

    Best tutorial about webpack I have ever seen
    Thanks bro

  • @cholo2605
    @cholo2605 10 місяців тому

    Thanks so much professor, i just discover you and i think you are the GOAT🐐

  • @aminam9201
    @aminam9201 3 роки тому

    the way you teach is clean in deep enough to get started.

  • @scoutn7370
    @scoutn7370 2 роки тому

    I had no idea Alan Cross knew about Webpack. :) Thanks for the informative video!

  • @meAnjani
    @meAnjani 10 місяців тому

    thank you so much Steve Griffith, it was very helpful and very easy to understand things that explained in this video.

  • @munishthakur8018
    @munishthakur8018 3 роки тому +2

    Loved this tutorial, very beautifully constructed , instead of installing evrything at once and overwhelming the students, concepts were introduced in an ordered fashion only when necessary. I truly understand Webpack now. Thanks !

  • @ikamy
    @ikamy 2 роки тому

    Thank you for not wasting my time, It's was super good

  • @cgarafulic
    @cgarafulic 2 роки тому +1

    Thank you Steve for such amazing explanation. Great started point to learn how webback works. Then it's up to the project needs what loaders and plug-ins to include.

  • @creatingwithcode1630
    @creatingwithcode1630 3 роки тому +3

    Excellent tutorial! I'm so glad that I found your channel.

  • @sagarkapr
    @sagarkapr 2 роки тому +1

    Dude you are awesome!!! Thanks for creating this. Looking forward to more content!

  • @licokr
    @licokr 2 роки тому

    The best webpack tutorial EVER

  • @thewpwing
    @thewpwing 2 роки тому

    Awesom explanation and walk with step by step. This is the best Webpack Getting Started. Thanks a lot.

  • @gektorix
    @gektorix 2 роки тому

    The only lesson that helped me set up webpack. Thank you very much. Please, make another one video of current webPack!)

  • @sujatkamal
    @sujatkamal 3 роки тому

    your service workers series was excellent lucidly explained.thanks

  • @sebastien1292
    @sebastien1292 2 роки тому

    This is the best tutorial I've watched on this topic. Thank you!

  • @marcinkalmar9964
    @marcinkalmar9964 2 роки тому

    When I was starting watching this tutorial I was knowing that I will understand finnaly what going on in web pack , i did not be wrong.

  • @bishwajeetpandey1570
    @bishwajeetpandey1570 Рік тому

    Wow sir you just clear the fundamentals of bundlers and it is really important to move forward .
    I request you 🙏 to make a video on parcel.js

  • @gyros9162
    @gyros9162 2 роки тому

    Thank you! I understand a lot from your video. As always laconic and meaningful. They say Node Sass deprecated and urge you to switch to Dart Sass, which is, anyway, available from npm by "npm install sass"

  • @taofeeqomotolani2311
    @taofeeqomotolani2311 2 роки тому

    This was really a great overview to Webpack. I followed the steps in the video and everything works alright except that when I make changes to the template.html file, it doesn't reflect live on the webpage except if I manually reload the page but when I make changes to the SCSS or JS files it's changes reflect live.

    • @taofeeqomotolani2311
      @taofeeqomotolani2311 2 роки тому +1

      Okay, all I had to do was change the static folder path to src

  • @mfrdbigolin
    @mfrdbigolin 2 роки тому +1

    Really good introduction to webpack.

  • @laughing-out-loudhd996
    @laughing-out-loudhd996 Рік тому

    That is really well explained.. Thank you prof

  • @essohanamalou7662
    @essohanamalou7662 2 роки тому

    thanks. You really made things easy to understand

  • @iwswordpress
    @iwswordpress 3 роки тому +1

    Superb! Actually helped me understand and wanting to use webpack. Thanks.

  • @serebniti
    @serebniti 3 роки тому

    Hello from Russia! I love your diction! Very comfortable!

  • @custercuster4918
    @custercuster4918 Рік тому

    Wow, what an amazing video, really appreciate what you've done

  • @johnm8358
    @johnm8358 3 роки тому +2

    Great tutorial as always, more webpack please ;)

  • @user-nz7zs1sy9e
    @user-nz7zs1sy9e 2 роки тому

    greate work! clear and concise, much better than reading the docs. tks!

  • @khaledoghli1894
    @khaledoghli1894 3 роки тому

    Thank you so much ,i have been waiting this tutorial from someone good in explain .i will watch this now .and i hope you cover the important thing . when we work in real project 💙

  • @abhishes
    @abhishes Рік тому

    Thanks .. very good introduction.

  • @prernamehra2343
    @prernamehra2343 2 роки тому

    Just loved it. 😍 Thanks for creating wonderful content. 🙏

  • @stefangriffin986
    @stefangriffin986 2 роки тому

    Super cool. Great in depth explanation. Thanks, I m good to go now 🤙🏻

  • @emrentoelluminiados
    @emrentoelluminiados Рік тому

    if you want to learn 'React', you should start with this content.

  • @hasnainabbasdilawar8832
    @hasnainabbasdilawar8832 2 роки тому +1

    Great explanation. Just a suggestion, adding timelines to your videos would be good.

  • @marcosotto8424
    @marcosotto8424 2 роки тому

    Great tutorial....thanks Steve...

  • @amithbhagat
    @amithbhagat 2 роки тому

    Thank you very much 🙏. Great tutorial. It helped me a lot.

  • @christopherpink842
    @christopherpink842 2 роки тому

    hello, if I have a html template ie temp.html that has multiple images , how do i import them to be bundled?
    cant find any solutions online, only solutions are single image, I have like 25 images, do i have to import into the app.js individually?

  • @robertapostoiu2272
    @robertapostoiu2272 2 роки тому

    Why do I have to save both the temp.html changes and the index.html that is being outputted? If i just save temp it doesn't work

  • @sab1102
    @sab1102 3 роки тому

    OMG loooved it!! Thank you so much!

  • @stanislavschaefer3233
    @stanislavschaefer3233 2 роки тому +1

    @25:34 replace "contentBase: path.resolve{__dirname, "dist"} => static: { directory: path.join(__dirname, "dist" }", otherwise you're gonna get an error and it won't compile.

  • @awabelmahe9700
    @awabelmahe9700 2 роки тому

    Thank you very much, this was really helpful.

  • @webmasterdev8692
    @webmasterdev8692 2 роки тому

    Excellent Awesome Great, I like man

  • @noni_shadow
    @noni_shadow 2 роки тому

    Thank you so much for this great tuto ❤

  • @BogacGuven
    @BogacGuven 3 роки тому

    As always amazing content. Thank you ❤

  • @mohamedyoussef8835
    @mohamedyoussef8835 2 роки тому

    Super Awesome explanation of very confusing topic ++++++++++ 🙂🙂

  • @ajdinzutic
    @ajdinzutic 2 роки тому

    Hi thanks for the cool video :) How do you manage Header/Footer or other Menus, which you want to share in all *.html Sites? I currently use it with a custom .js File, but it isn't very recommend for SEO. Can i build something which is stable with webpack5? So that i can later on use also Style with CSS or Tailwind itself?

  • @RamtinAlamdari
    @RamtinAlamdari 2 роки тому

    Well explained for beginners.

  • @nikza1936
    @nikza1936 2 роки тому

    real Professor !

  • @user-mo3cw6go7c
    @user-mo3cw6go7c 2 роки тому

    realy good video on this scary topic

  • @VanHaleNNoodle
    @VanHaleNNoodle 2 роки тому

    Thanks!
    Excellent video.

  • @alexpr6157
    @alexpr6157 3 роки тому +1

    If you get an error like "Invalid options object". Change ContentBase to static in devServer.

  • @dumchik7290
    @dumchik7290 2 роки тому

    If I use index.html, no issue. But if I change its name to app.html and open dev server, I see the listed directory in browser. From there I have to select app.html. How can dev server directly open app.html?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      That is more an issue of how the web works. index.html is the default file name for every website on every server. If no file name is provided then the webserver will return index.html. This was created as a standard because people cannot be expected to guess the names of your webpages.

  • @MichaelSalo
    @MichaelSalo 2 роки тому

    16:07 Does this mean that plugins run before loaders?

  • @saalimmushtaq3472
    @saalimmushtaq3472 2 роки тому

    very helpful tutorial

  • @josemunguia5660
    @josemunguia5660 3 роки тому

    Thanks for this great tutorial!

  • @yuvrajbiswas9702
    @yuvrajbiswas9702 2 роки тому

    Sir I want to add different components of jsx, props,arrays,Router,link etc in main.js. can you explain me that how's that possible?

  • @fazzyakamello
    @fazzyakamello 3 роки тому

    Thanks Prof. Love your work

  • @mahendraverma3459
    @mahendraverma3459 2 роки тому

    It is a great tutorial.

  • @ygvanz
    @ygvanz 3 роки тому

    You are the best of the best.

  • @christopherpink842
    @christopherpink842 2 роки тому

    THANK YOU VERY MUCH !!!!!!!!!

  • @khaledfarghly6480
    @khaledfarghly6480 2 роки тому

    Thanks, professor Steve.

  • @sachindramohansahay187
    @sachindramohansahay187 2 роки тому

    If we don't add webpack config file our file folder then it's important to add.
    Please complete webpack crash course video for ecommerce website.

  • @redisco100
    @redisco100 2 роки тому

    Агонь, красава!

  • @mdosmanfarooque1415
    @mdosmanfarooque1415 2 роки тому

    Thank you very much!!!

  • @ZenTechnologist
    @ZenTechnologist 2 роки тому

    Thank you Steve for your easy to follow tutorial 🙏🏾. My setup is 80% done and I understand it. Is there a way to set it up so that the css file is copied separately to the dist folder?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому +1

      You can set multiple entry and output points instead of just one.
      Often with webpack the CSS is being read and then injected directly into the HTML and/or imported through the JS. It gets compressed and injected.

    • @ZenTechnologist
      @ZenTechnologist 2 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 I ended up using the MiniCssExtractPlugin and loader, but I will explore this option too. Thanks

  • @husanisant
    @husanisant 2 роки тому

    Thanks! Nice! Great Tutorial!

  • @SykoSilver
    @SykoSilver 2 роки тому

    If it's something you'd find useful for your classes, could you do a video on using Webpack with Express & EJS? Thanks.

  • @MikeNugget
    @MikeNugget 2 роки тому

    I have a reasonable question: since this video tutorial literally is about 5th version of Webpack in 2021, why author writes options for devServer like `contentBase` and `watchContentBase`? There are no such options for Webpack 5 in official docs. So to make devServer work I had to remove `contentBase` and `watchContentBase` options and then I just added `static: path.resolve(__dirname, 'dist')`.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому +1

      Yes those were devserver options from version 4 that I missed. It was changed in the code gist and discussed in the comments already.

    • @timtech9361
      @timtech9361 2 роки тому +1

      Everything that is passed 6months via tutorial videos is 99% outdated. That is just the world of software development. That is why it is very important to read official documentation before diving into any tutorial.

  • @bizimungupascal4118
    @bizimungupascal4118 2 роки тому

    Thank you very much

  • @rickyu1978
    @rickyu1978 3 роки тому

    contentBase throws an error, it has been renamed to static. However, It seems with webpck 5.5 dev server is built in? am i wrong?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому +1

      Yes. contentBase was the old setting. static is the new name for that. Thanks. I've updated that in my sample file. The dev server is part of webpack.
      webpack.js.org/configuration/dev-server/

  • @kamals185
    @kamals185 2 роки тому

    how to use production mode in webpack

  • @abdullahalsakib7963
    @abdullahalsakib7963 3 роки тому +1

    Hope sir will make some tutorial on Redux and Redux Toolkit too 😄. It will really be helpful

  • @patrickoneill6498
    @patrickoneill6498 3 роки тому

    One thing conspicuously absent from these video and all webpack tutorial videos - watching html files, recompiling and then live reloading. Am I right in thinking this is not supported in webpack?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      It's not something that I would think to do with webpack. Generally speaking webpack is used with JS based projects that are generating the HTML. HTML templates are used or other tools that may have server-side rendering or generated static pages. But if my site was built with a bunch of static HTML files then I wouldn't think to try and bundle it was an app with webpack.

  • @devdude7607
    @devdude7607 2 роки тому

    I just don't understand the point of using Webpack over Parcel, other than the mighty deep configurations. There is just too much of config to start a project with. :/ What do you think? And Thank you so much for walking thorough this like no others!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому +1

      I have no opinion about one over the other.
      Any build tool that you use is going to take time to learn. Once you have a solution that does everything that you need, stick with it.

    • @devdude7607
      @devdude7607 2 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Thank you!

  • @heyyayesh
    @heyyayesh 2 роки тому

    Great tutorial! I still have one doubt though. When I insert an element into the template html file it doesn't load on the webpage. Do i need another loader for that to work?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому +1

      Images need to be imported through your JavaScript to get copied over to the distribution folder.

    • @heyyayesh
      @heyyayesh 2 роки тому

      @@SteveGriffith-Prof3ssorSt3v3 Thanks for replying! I have imported in into the .js file and when i insert the image into the DOM from Js it works but when i add an img tag in the template html file and set the image path as the src of that tag it doesn't load on the webpage. However i do see an image in the dist folder with hashed name. I wish i could share more info about my query but I can't here. Any advice will be extremely helpful. Thanks.

  • @laughxout9175
    @laughxout9175 2 роки тому +1

    Thank you for awesome content!
    Is HtmlWebpackPlugin the same as pug? Can I use both?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      Pug is a tempting tool the other is a webpack plugin they are not the same thing.

    • @laughxout9175
      @laughxout9175 2 роки тому +1

      Steve can you please tell how I should write pug and sass in webpack.config.js.

  • @koraytugay
    @koraytugay 2 роки тому

    14:27 Are you sure? I think plugins is a list of objects, not a list of JavaScript functions..

  • @cigmaian7139
    @cigmaian7139 2 роки тому

    at minute 31:19 how he reset the server? how to call c^C?

  • @BradleyKisia
    @BradleyKisia 2 роки тому

    Nice!!!

  • @techwriting6493
    @techwriting6493 2 роки тому

    How can I delete a folder in vs code that I've already imported to VS code?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      Not sure what you mean. VSCode only shows files and folders that are on your operating system. If you delete a file from your OS it will disappear in VSCode.

    • @techwriting6493
      @techwriting6493 2 роки тому +1

      Thank you

  • @nematjonabdulloev3568
    @nematjonabdulloev3568 3 роки тому

    Is it worth to migrate from webpack 4 now? I mean those dependencies used in project. In my opinion it is pretty early yet. What do you think teacher?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому +1

      Webpack 5 is now the official version. It went through a long beta period first.
      No need to change older projects but anything you start now should use version 5.

    • @nematjonabdulloev3568
      @nematjonabdulloev3568 3 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Got it. Now that's clear for me 👍.

  • @sometimespecial3750
    @sometimespecial3750 2 роки тому

    it's not working, please solve it......................
    [webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
    - options has an unknown property 'watchContentBase'. These properties are valid:

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      As per other comments in here there were a couple changes from version 4 to 5.
      DevServer has been supported since version 4, but there are a couple changes to the options.
      webpack.js.org/configuration/dev-server/
      The code gist has been updated.

    • @sometimespecial3750
      @sometimespecial3750 2 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Thank you😍💕💕

  • @Kanexxable
    @Kanexxable 3 роки тому

    could you do a more in depth course i don't know the most optimal and professional way of setting up webpack. I mean mine does work but reading the docs is too confusing. I'm an aspiring front end dev.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      The way you set up webpack depends entirely on the project you are building. There is not simply one way to set it up. It depends on the technologies that you are using. It the flexibility of webpack that makes it so powerful (and so challenging to learn).
      There is a good boilerplate linked in the description. A boilerplate is a good starting point.

  • @leilagueno3183
    @leilagueno3183 2 роки тому

    what is that arrow symbol at 20:53?

  • @husainmwasfi4262
    @husainmwasfi4262 2 роки тому

    "npm run build" not working
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      Are you in the right folder?

    • @husainmwasfi4262
      @husainmwasfi4262 2 роки тому

      [webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
      - options has an unknown property 'watchContentBase'. These properties are valid:
      object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, static?, watchFiles?, webSocketServer? }

    • @husainmwasfi4262
      @husainmwasfi4262 2 роки тому

      devServer: {
      contentBase: path.resolve(__dirname, 'dist'),
      writeToDisk: true,
      port: 5001, // default 8080
      open: true,
      hot: true,
      // this is for server to refresh when you change files in /build (not required normally)
      watchContentBase: true,
      },

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      @@husainmwasfi4262 This was discussed in other comments and was updated in the code Gist.

  • @bornoahmed4004
    @bornoahmed4004 2 роки тому

    good job.

  • @fadhilh3931
    @fadhilh3931 2 роки тому

    Is webpack created for SPA type of website? Because it bundles up a ton of JS into single file. So it's perfect case for SPA.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      Webpack works well for SPA but also for other types of websites too. All depends on what you are building and how you configure Webpack.

    • @fadhilh3931
      @fadhilh3931 2 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Thanks for answering, I'm a complete newbie in webpack, why we need to import css and svg into JS? For example, can we just put the css link stylesheet in the html and put the class name to JS? I don't really get the concept

  • @majdibrahem1399
    @majdibrahem1399 2 роки тому

    I love you bro

  • @coderjeet
    @coderjeet 2 роки тому

    Good tutorial!

  • @eugeniogonzato
    @eugeniogonzato 3 роки тому

    Thank you

  • @chakibbensari1850
    @chakibbensari1850 3 роки тому

    Thanks a lot for this tutorial.. it's a legendary tutorial for me !
    i have just a question, i am not able to start the local server unless i remove the static propert from devSever configuration object
    Can you help me understand please ?
    This is my object config :
    devServer: {
    static: path.resolve(__dirname, 'dist'),
    port: 5001, //default 8080
    open: true,
    hot: true,
    watchContentBase: true,
    }
    Thanks

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      are you importing the path module at the top of your file?

    • @chakibbensari1850
      @chakibbensari1850 3 роки тому

      @@SteveGriffith-Prof3ssorSt3v3 yes all is as it was on the git. When i remove the static propert all goes fine but when it is there webpack tells me that no additionnal properties shoud be added to options (for devServer)

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      @@chakibbensari1850 not sure what is causing that for you

  • @ahmadreza2189
    @ahmadreza2189 3 роки тому

    Thank you very much,please part youre videos