Slide 1

Slide 1 text

W E B PA C K I S A M A Z I N G * @ J O S H H U N T

Slide 2

Slide 2 text

Webpack is a modern build tool for web apps

Slide 3

Slide 3 text

*Can be a bit of a pain to manage.

Slide 4

Slide 4 text

Not just a JS bundler. Wants to have complete understanding of your web app.

Slide 5

Slide 5 text

Not a task runner. Doesn't replace Gulp.

Slide 6

Slide 6 text

First class support for transforming dependencies

Slide 7

Slide 7 text

Plugin-orientated architecture

Slide 8

Slide 8 text

D E M O

Slide 9

Slide 9 text

M O R E W E B PA C K

Slide 10

Slide 10 text

url-loader: Copy static assets to build directory and reference via uri

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

svg-react-loader: Load SVG files as React components

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Faster source maps

Slide 17

Slide 17 text

Fix relative import hell with resolve.root

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

DefinePlugin lets you define text replacements within all files

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

M A N A G I N G A S S E T S

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Webpack abstracts away the URI of the resource

Slide 29

Slide 29 text

Automatically hash assets for long and auto-busting cache

Slide 30

Slide 30 text

Long Cache + Cache Busting 101 1. Append ID to each file e.g. logo-v1.png 2. Set Expires header on files to 1 year 3. *browsers will now cache assets forever* 4. When files change, change the ID e.g. logo-v2.png 5. ‘Invalidates’ logo browser cache, browsers download new one

Slide 31

Slide 31 text

Webpack can do all this automatically

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Use a plugin to create an asset manifest file that the server reads to get the URL

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

We wrote our own: gist.github.com/joshhunt Another is webpack-manifest-plugin on npm.

Slide 38

Slide 38 text

[hash] is fast because it represents the entire build. Use during development. [chunkhash] is a hash of individual assets, so it’s slow. Use for production.

Slide 39

Slide 39 text

W E B PA C K O N T H E S E RV E R

Slide 40

Slide 40 text

React runs great on the server. require(logo.png) doesnt.

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Some solutions are convoluted and hacky - Babel plugins and require hooks

Slide 43

Slide 43 text

Just Webpack your server.

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

It’s weird and feels kinda wrong. But it’s relatively simple and straightforward.

Slide 46

Slide 46 text

T E S T I N G W E B PA C K I F I E D C O D E

Slide 47

Slide 47 text

It’s quicker and easier to test React components on the server with Node

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

You can't require images in Node.

Slide 50

Slide 50 text

Build tests with Webpack!

Slide 51

Slide 51 text

NO! ITS SOOOOOOO SLOW!

Slide 52

Slide 52 text

Quick feedback cycle is crucial for healthy testing practices

Slide 53

Slide 53 text

Simulate resolve.root with app-module-path

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Stub require(.png) on Node with node-hook

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Mock require(.styl) on Node with proxyquire

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

M A N A G I N G M U LT I P L E C O N F I G S W I T H O U T S TA B B I N G Y O U R E Y E S O U T ( M O S T LY )

Slide 60

Slide 60 text

As your project ‘matures’, Webpack configs get bigger

Slide 61

Slide 61 text

Dev + Prod gives you two variants

Slide 62

Slide 62 text

With server + client, you now have four Dev + Prod gives you two variants

Slide 63

Slide 63 text

Having four seperate, slightly varying 100+ line configs is madness

Slide 64

Slide 64 text

Solution? Webpack config generator!

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

C O D E

Slide 67

Slide 67 text

It’s not the prettiest code, but IMHO it’s probably the best solution to a shitty problem

Slide 68

Slide 68 text

F I N .

Slide 69

Slide 69 text

F I N . Q U E S T I O N S ?