Slide 1

Slide 1 text

CONFIDENT ASSET DEPLOYMENTS WITH WEBPACK & DJANGO SCOTT BURNS (@SCOTTSBURNS) DJANGOCON US 2016 #CONFIDENT-DEPLOYS

Slide 2

Slide 2 text

SHHH, I HAVE A SECRET @scottsburns Confident Asset Deployments

Slide 3

Slide 3 text

OWAIS LONE GITHUB.COM/OWAIS

Slide 4

Slide 4 text

̣ PHILOSOPHY ̣ SPECIFICS ̣ PHILOSOPHY @scottsburns Confident Asset Deployments

Slide 5

Slide 5 text

CONFIDENT ASSET DEPLOYMENTS? @scottsburns Confident Asset Deployments

Slide 6

Slide 6 text

DEPLOYMENTS Confident Asset Deployments @scottsburns

Slide 7

Slide 7 text

̣CHANGES ̣FEATURES ̣FIXES Confident Asset Deployments @scottsburns

Slide 8

Slide 8 text

ASSET @scottsburns Confident Asset Deployments

Slide 9

Slide 9 text

̣JAVASCRIPT ̣CSS ̣IMAGES @scottsburns Confident Asset Deployments

Slide 10

Slide 10 text

CONFIDENT @scottsburns Confident Asset Deployments

Slide 11

Slide 11 text

̣EASY TO BEGIN ̣REVERSIBLE ̣FAST @scottsburns Confident Asset Deployments

Slide 12

Slide 12 text

̣AUTOMATED ̣FEW 3RD PARTIES ̣TESTED @scottsburns Confident Asset Deployments

Slide 13

Slide 13 text

WHY NOW? Confident Asset Deployments @scottsburns

Slide 14

Slide 14 text

TOOLCHAINS HAVE IMPROVED Confident Asset Deployments @scottsburns

Slide 15

Slide 15 text

COMMUNITIES MOVE AT DIFFERENT SPEEDS Confident Asset Deployments @scottsburns

Slide 16

Slide 16 text

BUILD BRIDGES, NOT WRAPPERS Confident Asset Deployments @scottsburns

Slide 17

Slide 17 text

CODE PLEASE Confident Asset Deployments @scottsburns

Slide 18

Slide 18 text

WEBPACK? Confident Asset Deployments @scottsburns

Slide 19

Slide 19 text

Confident Asset Deployments @scottsburns https://webpack.github.io/ WEBPACK

Slide 20

Slide 20 text

$ npm install -s -g \ webpack \ webpack-bundle-tracker Confident Asset Deployments @scottsburns INSTALLATION

Slide 21

Slide 21 text

WEBPACK.CONFIG.JS Confident Asset Deployments @scottsburns var path = require("path") var webpack = require('webpack') var BundleTracker = require('webpack-bundle-tracker') module.exports = { entry: { app: ’./static/index.js’ }, output: { path: path.resolve('./static/bundles/'), filename: "[name]-[hash].js", },...

Slide 22

Slide 22 text

WEBPACK.CONFIG.JS Confident Asset Deployments @scottsburns ... plugins: [ new BundleTracker( {filename: ‘./webpack-stats.json’}), ], module: { loaders: […] // not enough time :( }, }

Slide 23

Slide 23 text

$ webpack —-config \ webpack.config.js Confident Asset Deployments @scottsburns BUILD THE BUNDLE

Slide 24

Slide 24 text

{ “status":"done", “chunks”: { “app”: [{ “name": "app-1234567890.js", “path”: “/app/static/bundles/ app-1234567890.js”} ] } } Confident Asset Deployments @scottsburns WEBPACK-STATS.JSON

Slide 25

Slide 25 text

Confident Asset Deployments @scottsburns

Slide 26

Slide 26 text

app/ ├─ manage.py ├─ webpack.config.js ├─ webpack-stats.json ├─ static │ ├─ index.js │ └─ bundles/ # git ignore │ └─ app-1234567890.js └─ app/ └─ urls.py, app.wsgi, etc… Confident Asset Deployments @scottsburns STRUCTURE

Slide 27

Slide 27 text

...
...
</body> Confident Asset Deployments @scottsburns INDEX.HTML

Slide 28

Slide 28 text

$ pip install \ django-webpack-loader Confident Asset Deployments @scottsburns

Slide 29

Slide 29 text

... STATICFILES_DIRS = ( ‘static’, ) ... Confident Asset Deployments @scottsburns SETTINGS.PY

Slide 30

Slide 30 text

... WEBPACK_LOADER = { 'BUNDLE_DIR_NAME': 'bundles/', ‘STATS_FILE': 'webpack-stats.json', } ... Confident Asset Deployments @scottsburns SETTINGS.PY

Slide 31

Slide 31 text

... INSTALLED_APPS = ( ... ‘webpack_loader', ... ) ... Confident Asset Deployments @scottsburns SETTINGS.PY

Slide 32

Slide 32 text

{% load render_bundle from webpack_loader %} ...
...
{% render_bundle ‘main' %} Confident Asset Deployments @scottsburns INDEX.HTML

Slide 33

Slide 33 text

...
...
</body> Confident Asset Deployments @scottsburns (RENDERED) INDEX.HTML

Slide 34

Slide 34 text

Confident Asset Deployments WEBPACK-STATS.JSON INDEX.HTML APP-1234567890.JS @scottsburns

Slide 35

Slide 35 text

Confident Asset Deployments WEBPACK-STATS.JSON INDEX.HTML APP-0987654321.JS @scottsburns

Slide 36

Slide 36 text

DON’T SERVE ASSETS FROM DJANGO Confident Asset Deployments @scottsburns

Slide 37

Slide 37 text

WHY NOT (PURE) STATICFILES? Confident Asset Deployments @scottsburns

Slide 38

Slide 38 text

̣PRODUCTION ENV ̣SLOW ̣POST-PROCESSORS @scottsburns Confident Asset Deployments

Slide 39

Slide 39 text

SEPARATE THE CONCERNS Confident Asset Deployments @scottsburns

Slide 40

Slide 40 text

FRONT-END DEVS WILL ❤ YOU Confident Asset Deployments @scottsburns

Slide 41

Slide 41 text

(DEV)OPS WILL ❤ YOU Confident Asset Deployments @scottsburns

Slide 42

Slide 42 text

NEW DEVS WILL ❤ YOU Confident Asset Deployments @scottsburns

Slide 43

Slide 43 text

̣BUILD ̣DEPLOY ̣REPEAT @scottsburns Confident Asset Deployments

Slide 44

Slide 44 text

THANK YOU ❤ @scottsburns Confident Asset Deployments