Webpack Encore has been around for more than 1 year, and it's been a huge success! In this presentation, we'll learn some lessons from the past year and get a look at the brand new features supported in the latest version of Encore.
SymfonyCasts.com > Symfony evangelist… Fanboy > Husband of the much more talented @leannapelham symfonycasts.com twitter.com/weaverryan Yo! I’m Ryan! > Father to my much more charming son, Beckett
console.log('Webpack will package all this up'); console.log('And output 2 files: app.js and app.css'); A tool that “packages” your app up into one CSS and one JS file
from './common/random_word'; console.log('The word of the day is: '+getRandomWord()) // assets/js/common/random_word.js - module.exports = function() { + export default function() { const words = ['foo', 'bar', 'baz']; return words[Math.floor(Math.random() * words.length)]; }
Chunks” support > browserlist support in package.json > Dynamic imports (code splitting) syntax support > Smarter version checking system > Babel 7 out of the box Webpack Encore 0.21.0
Encore.getWebpackConfig(); {# templates/base.html.twig #} {% block javascripts %} <script src="{{ asset('build/runtime.js') }}"></script> <script src="{{ asset('build/app.js') }}"></script> {% endblock %} With a runtime chunk, if multiple entry files require the same module, they receive the same object
var $ = require('jquery'); $('.item').tooltip(); Will this work? Does the jquery module have the tooltip in checkout.js? enableSingleRuntimeChunk() Yes :D disableSingleRuntimeChunk() No :)
asset('build/vendor~a33029de.js') }}"></script> <script src="{{ asset('build/vendor~ea1103fa.js') }}"></script> <script src="{{ asset('build/app.js') }}"></script> {% endblock %} All of these files are needed to for the “app” entry to function How are we supposed to know what script & link tags we need?
}); // assets/js/common/external_linker.js import $ from 'jquery'; import '../../css/external_link.css'; export default function(linkEl) { $(linkEl).addClass('clicked'); } The code from external_linker.js will not be included in the app.js It will be loaded via AJAX when needed (including the CSS file!)