WebpackTutorial icon indicating copy to clipboard operation
WebpackTutorial copied to clipboard

My issue is that this tutorial is too awesome

Open Maximilianos opened this issue 9 years ago • 17 comments

Seriously. I've been working with Webpack for over a year, putting stuff together from bits over there, bits over here. After reading this tutorial I finally feel like its all coming together. This is a tutorial like all tutorials should be: focus on being simple, tackle one problem at a time; basic building blocks that add up, step by step, to making you feel like a developer wearing a jetpack!

Thank you :smile:

PS: feel free to close this issue whenever.

Maximilianos avatar Feb 22 '16 10:02 Maximilianos

I might just never close it haha. Thank you for the warm words!

AriaFallah avatar Feb 22 '16 14:02 AriaFallah

Thank you @AriaFallah! This was the tutorial that helped me jump into Webpack and understand how to set it up for live reloads and rapid development. When do you think you will have one with react? I know that with this tool you can update component's code without loosing the state.

Many thanks! -Alex

AlexKvazos avatar Feb 23 '16 14:02 AlexKvazos

@AlexKvazos

For the time being, I've become really busy, and I don't think I'll put out future parts for at least another week or two.

Another part of the reason I've held off is because it's extremely trivial to finally hook up HMR to React, and I've been wanting to find out if there's other content I can add to part3.

However, since I just said it was easy, I might as well put up a quick example. I haven't tested this, but the process would be something like this:

Using https://github.com/gaearon/react-transform-boilerplate as a reference:

Add these two plugins to your webpack config (although you should already have the HotModuleReplacement one):

plugins: [
  // ...other plugins
  new webpack.HotModuleReplacementPlugin(),
  new webpack.NoErrorsPlugin()
],

Install these babel presets:

npm install --save-dev babel-preset-react
npm install --save-dev babel-preset-react-hmre 

Change your .babelrc to

{
  "presets": ["react", "es2015", "stage-2"],
  "env": {
    "development": {
      "presets": ["react-hmre"]
    }
  }
}

And I think that should be it.

Again, I'm not sure if I got everything right because, unlike the tutorials, I wrote this quickly without testing. If you actually try this out, let me know if it works.

At the very least I hope that helps.

AriaFallah avatar Feb 23 '16 14:02 AriaFallah

same here, thanks for putting this together.

altaywtf avatar Apr 23 '16 12:04 altaywtf

Hey@AriaFallah, Thank you this series on webpack is shining a new light for how I understand webpack. One thing I noticed is that hot reloading only worked when I changed my npm script from "devbuild": "webpack-dev-server --config webpack.config.dev.js" to "devbuild": "webpack-dev-server --hot --inline --config webpack.config.dev.js" with --hot --inline

Not sure if that's been affecting other users.

felicedeNigris avatar May 03 '16 15:05 felicedeNigris

@felicedeNigris that's interesting. That's how you would do hot reloading from the CLI if you didn't have it configured in you webpack.config.dev.js, but if you have the HotModuleReplacementPlugin and the hot: true for your dev server config, it should be working.

If that doesn't work check out: https://medium.com/@rajaraodv/webpacks-hmr-react-hot-loader-the-missing-manual-232336dc0d96#.cujh3xov7

It's very well written.

AriaFallah avatar May 03 '16 16:05 AriaFallah

Thanks for sharing the link !

felicedeNigris avatar May 03 '16 17:05 felicedeNigris

支持下台湾的同胞,很受用,请继续加油!

AyumiKai avatar Jun 14 '16 01:06 AyumiKai

Ok, now even I can use webpack after this tutorial. Thanks

dhoomm avatar Jun 24 '16 09:06 dhoomm

Best webpack tutorial i'v ever seen !!! Thanks!

zsuswy avatar Jul 20 '16 08:07 zsuswy

I wanted to say thank you as well. Absolutely wonderful tutorial for someone diving into front end!

rcmontoy avatar Aug 03 '16 16:08 rcmontoy

Hey, this tutorial is awesome, i'm really new to webpack and i have a question.

When i run dev, it's supposed to output the files in dist folder? because when i use build i get the files in dist but dev doesn't.

Silentz0r avatar Nov 28 '16 20:11 Silentz0r

@Silentz0r

Hey, nice observation! I was also confused about this when I first started. First you should understand that you're running two different commands:

"build": "webpack --config webpack.config.prod.js",
"dev"  : "webpack-dev-server --config webpack.config.dev.js"

When you run the dev config, you're not running webpack, you're running the webpack-dev-server. The dev server has no need for the files to be output since it uses them directly itself through webpack's API. Specifically, whoever wrote webpack-dev-server does require('webpack') inside their code, and uses it from inside their code instead of from the command line. When doing it like this, they don't really have the need to generate files as I would guess that they decided the overhead of writing a file was not worth it during development (files are changing often so no point constantly rewriting them).

When you run build your intention is to generate the files for distribution by any static file server. You need actual files for this unlike webpack-dev-server that can operate without them.

Does that make sense?

AriaFallah avatar Nov 28 '16 21:11 AriaFallah

Ohh, i get it now! It was so confusing to me and had to ask. I don't know if i did something wrong or the fact i'm using Node v7 and didnt know could be issues with webpack with this version OR i don't understand quite well how the HMR works but when i apply the changes to the HTML the console shows me that's HMR is hot reloading the app but i dont see the changes applied. Ex. A button i did in the HTML i changed the name from OK to Submit.

Edit: When i refresh the page (F5) i can see the html changed.

Is this a expected behavior or i'm doing something wrong? Thank you again for this tutorial!

Silentz0r avatar Nov 28 '16 21:11 Silentz0r

@Silentz0r

It's a bit hard to understand what you're asking. I would recommend either asking on Stack Overflow, or making a new issue with more details.

AriaFallah avatar Nov 28 '16 22:11 AriaFallah

@AriaFallah

Sure, thank you anyway, i'm kinda new to these stuffs and it's hard for me to explain it and english is not my native languague, heh.

Silentz0r avatar Nov 28 '16 22:11 Silentz0r

Awesome! I was try understand webpack many times before but this is really elegant tuts) I thing you can start own courses and even get some profit cauz you can extend this articles and create a good info product) But yes that's awesome how easy you explain hard for me things!

SashaDesigN avatar Jun 01 '17 20:06 SashaDesigN