@weaverryan
With your friend Ryan Weaver
Modern UIs with UX,
a little JS & Zero Node
Slide 2
Slide 2 text
> Member of the Symfony docs team
> Husband of the talented and
beloved @leannapelham
symfonycasts.com
twitter.com/weaverryan
Howdy there!! I’m Ryan!
> Author person at
SymfonyCasts.com
Slide 3
Slide 3 text
Your new Build System:
Your browser
Part 1
@weaverryan
import Duck from './duck.js';
const duck = new Duck('Waddles');
duck.quack();
public/app.js
This just works!
Slide 7
Slide 7 text
All browsers now support
import, ES6 class syntax,
etc**
** Ok, not IE11, but that is less than 0.5%!
Slide 8
Slide 8 text
So then… why do I need
ANY tools?
Slide 9
Slide 9 text
Two Problems
1) Versioned Filenames
2) Importing 3rd Party Packages
import 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
Slide 10
Slide 10 text
Hello AssetMapper
(Experimental in 6.3)
Part 2
@weaverryan
Slide 11
Slide 11 text
Asset Mapper Part #1 of 2:
Exposing & Versioning Assets
@weaverryan
Slide 12
Slide 12 text
If my photo updates, my
fi
lename will update
automatically!"
Slide 13
Slide 13 text
How… did that work?
/assets/* is served by an internal Symfony listener
dev:
prod:
Run php bin/console asset-map:compile to physically
write all
fi
les into the public/assets/ directory
/assets/images/duck-3c16d9220694.png
Slide 14
Slide 14 text
Asset Mapper Part #2 of 2:
Importmap
@weaverryan
Slide 15
Slide 15 text
How can we use 3rd party
packages?
@weaverryan
Slide 16
Slide 16 text
import { Alert } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
const alert = new Alert(element);
This works
Yikes!
Slide 17
Slide 17 text
???
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
Now this works ✅
import { Alert } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
import { Alert } from 'bootstrap';
const alert = new Alert(element);
Not as smooth, but documented
Or download into assets/vendor/, include & commit.
Slide 29
Slide 29 text
Sass? Tailwind? ✅ (see docs about building)
JSX, Vue, TypeScript? ❌ (actually, yes, but a build system may be better)
Production Ready? ✅ (and performant)
Works on all browsers? ✅ (except for ancient browsers, like IE 11)
Slide 30
Slide 30 text
Does it combine and
minify the assets?
Slide 31
Slide 31 text
No!
By Design! Yay!
Slide 32
Slide 32 text
gzip/compress Assets
Do it on your web server / Cloud
fl
are
Combining Assets
Not needed**
Use an HTTP/2 powered web server / Cloud
fl
are
** not combining can even *help* performance:
if a single
fi
le is changed, users will only need to download that one
fi
le.
Slide 33
Slide 33 text
Part 3
Turbo: You're Handier
Than I Thought
@weaverryan
Slide 34
Slide 34 text
Create rich frontends while minimizing
the need for custom JavaScript
Goal
✅ Asset Mapper: Ciao node!
s
Turbo + Sprinkle of Stimulus
square
Live Components
Slide 35
Slide 35 text
https://bit.ly/30-days-hotwire
Slide 36
Slide 36 text
Need:
Even MORE demos on ux.symfony.com
@weaverryan
Slide 37
Slide 37 text
@weaverryan
Part 4
Symfony UX:
2.8 & 2.9
Slide 38
Slide 38 text
Symfony UX 2.8
@weaverryan
Slide 39
Slide 39 text
Two New Components
symfony/ux-translator
symfony/ux-svelte
import { trans, NUM_OF_APPLES } from '../translator';
trans(NUM_OF_APPLES, {
apples: 2
})
Slide 40
Slide 40 text
Live Components
* Smart Rendering System
* Communication between components: emit()
* First class data serializing & invalid data handling
* … lot's more!
Slide 41
Slide 41 text
New Demos:
ux.symfony.com/live-components
@weaverryan
UX 2.9
StimulusBundle
AssetMapper Support!
{{ stimulus_* }} functions moved out of
WebpackEncoreBundle and into StimulusBundle.
Slide 47
Slide 47 text
Yes, this means you can use Chart.js,
LiveComponents, Autocomplete, etc
entirely by writing PHP (no node!)
Slide 48
Slide 48 text
No content
Slide 49
Slide 49 text
#[AsLiveComponent()]
class DonutChart
{
use DefaultActionTrait;
#[LiveProp(writable: true)]
public int $slices = 5;
public function __construct(
private ChartBuilderInterface $chartBuilder,
) {
}
public function getChart(): Chart
{
$chart = $this->chartBuilder->createChart('doughnut');
$chart->setData(...);
return $chart;
}
}
Slide 50
Slide 50 text
How many slices?
{{ render_chart(this.chart) }}
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
We've come a long way…
@weaverryan
Slide 53
Slide 53 text
Symfony Cat Barcelona 2016
Slide 54
Slide 54 text
That's no longer a given!
@weaverryan
Slide 55
Slide 55 text
Browsers
Importmaps, import, ES6
features
HTTP/2 Requests download in parallel
AssetMapper Asset versioning + Extra DX
Slide 56
Slide 56 text
RIP Build Systems?
React, Vue, Next.js, etc
Tailwind / Sass
TypeScript
use their tools to build
use its tools to build
best served using their build system / a build system
Slide 57
Slide 57 text
Hotwire: HTML over the Wire
Alternative Path
HTML in templates , 0 Node , low custom JS
Slide 58
Slide 58 text
AssetMapper ❌ build system / node
Symfonycasts tutorial coming this month!
Slide 59
Slide 59 text
Turbo
Remove full page
reloads & more*
https://bit.ly/30-days-hotwire
SymfonyCasts.com/turbo
❌
Slide 60
Slide 60 text
Stimulus
A sprinkle of
custom JavaScript
SymfonyCasts.com/stimulus
🧁
Slide 61
Slide 61 text
LiveComponents
Swiss-Army Knife:
Make your Twig templates
reload live on the site.
🗡
Symfonycasts tutorial coming soon!