Webpack is the fundamental building block of all modern Javascript application frameworks. While being flexible and powerful its plain configuration can be quite hard to understand if you just want things to "work like expected". Symfony's opinionated webpack wrapper "Encore" allows you to setup a flexible asset pipeline with 20 lines of code. This talk and its supporting git repo shows some of the concepts and ends up with a fully working Symfony 4.1 application utilizing a combined React, Vue.js and jQuery (sic) frontend. https://github.com/elmariachi111/encore-demo
7. 7
var $ = require('jquery');
var _ = require('lodash');
var moment = require('moment');
class Clock {
constructor($el) {
this.time = moment();
this.$el = $el;
}
getServerTime() {
$.get('http://fixed.url.com', (err, res) => {
this.time = moment(res.time)
this.$el.text(this.time.format("HH:ii"))
})
}
}
var clock = new Clock($('#clock-div'));
clock.getServerTime();
module.exports = clock;
some recent javascript.
$ gulp build
<script src="app.js"></script>
8. 8
What I really need
•latest Javascript language features
•dependency management
•SCSS compilation
•live browser reloading
•debugging in the browser
•support for old frameworks
•don’t take care for old browsers
•fast loading times on production
•fast build times
•instantly useable by new team members
13. 13
•initial setup = no brainer
•Javascript files are the root of truth
•require scss, images, fonts, data, templates
•webpack can take care of
•JS transpilation
•browser compatibility & polyfilling
•image optimization
•SCSS compilation & extraction
•asset copying / concatenation
webpack core
14. 14
•babel integration
•write modern javascript
•transpile Typescript
•sourcemaps
•style inlining / css components
•versioning
•long term caching
•tree shaking
•~ dead code removal
•chunk control
•common chunks
•intelligent entrypoint commons
•enables framework syntaxes like
•React JSX
•Vue single file components
•developer experience
•file watching
•dev-server (reload on build)
•HMR (inject changes)
•code metrics
webpack advanced
24. 24
•Webpack 2 -> Webpack 4
•“shared commons entries” -> split chunks plugin
•dedicated vendor / client code chunks for entries
•“vendors.js & manifest.json” will be replaced with “entrypoints.json”
•every page gets exactly what it needs
•shared runtime chunk
•contains the webpack runtime for all pages
•dynamic imports (lazy loading specialized libraries / features)
•Handlebars loader built in
upcoming in the next release
25. 25
•massively reduces effort to enable modern frontend features
•by being highly opinionated
•integrates perfectly into Symfony applications
•the simplest way to enable modern frontend support
•perfect tool to start migrating old frontend code
•not so great to start a SPA/PWA/AMP project (use vue.cli or c-r-app instead)
•it just generates configuration
•you can always add your own config
•simple to “down”grade to plain webpack
•you can even use it outside a Symfony context
•the current release is stable and production ready.
•don’t use the bleeding edge master yet!!
wrap up
26. Turbine Kreuzberg GmbH
Ohlauer Straße 43
10999 Berlin
ASSET MANAGEMENT
FOR THE REST OF US.
@stadolf
#turbinejetzt
hello@turbinekreuzberg.com
https://github.com/elmariachi111/encore-demo