Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vite & TYPO3

Vite & TYPO3

modernes, vielseitiges Frontend-Setup mit Hot Reload

Link zur Extension: https://github.com/s2b/vite-asset-collector

Dieser Talk stammt vom TYPO3 Camp Berlin-Brandenburg 2023.

Simon Praetorius

June 03, 2023
Tweet

More Decks by Simon Praetorius

Other Decks in Programming

Transcript

  1. hire me for your project! Simon Praetorius 13 Jahre TYPO3

    in Agenturen OpenSource: ✦ Fluid Components ✦ Vite AssetCollector ✦ Fluid Maintainer Team selbstständig seit 1. Juni
  2. 1) Vite kennenlernen 2) Vite einrichten 3) Vite in TYPO3

    integrieren 4) Demo Simon Praetorius Vite & TYPO3
  3. Zero-Config-Support für TypeScript, PostCSS, SASS und LESS PlugIns für React,

    Preact, Vue, Svelte und Lit kann umfangreich konfiguriert werden (muss aber nicht) flexibel Simon Praetorius Vite & TYPO3
  4. Dev Server File Watcher Live Reload und Hot Module Replacement

    vite ddev vite-serve Simon Praetorius Vite & TYPO3 JS Bundler basiert auf Rollup.js Backend-Integration über manifest.json vite build &
  5. gute Mischung: opinionated und flexibel schlank und mächtig aktive Weiterentwicklung

    stetig zunehmende Verbreitung Warum Vite? Simon Praetorius Vite & TYPO3
  6. vite.config.js Simon Praetorius Vite & TYPO3 import { defineConfig }

    from "vite" import autoOrigin from "vite-plugin-auto-origin" export default defineConfig({ base: "", build: { manifest: true, rollupOptions: { input: "packages/sitepackage/Resources/Private/Main.entry.js", }, outDir: "public/_assets/vite/", }, plugins: [ autoOrigin() ], publicDir: false, });
  7. import { defineConfig } from "vite" import autoOrigin from "vite-plugin-auto-origin"

    export default defineConfig({ base: "", build: { manifest: true, rollupOptions: { input: "packages/sitepackage/Resources/Private/Main.entry.js", }, outDir: "public/_assets/vite/", }, plugins: [ autoOrigin() ], publicDir: false, }); Input / Output Simon Praetorius Vite & TYPO3
  8. import { defineConfig } from "vite" import autoOrigin from "vite-plugin-auto-origin"

    export default defineConfig({ base: "", build: { manifest: true, rollupOptions: { input: "packages/sitepackage/Resources/Private/Main.entry.js", }, outDir: "public/_assets/vite/", }, plugins: [ autoOrigin() ], publicDir: false, }); Manifest-Datei Simon Praetorius Vite & TYPO3
  9. import { defineConfig } from "vite" import autoOrigin from "vite-plugin-auto-origin"

    export default defineConfig({ base: "", build: { manifest: true, rollupOptions: { input: "packages/sitepackage/Resources/Private/Main.entry.js", }, outDir: "public/_assets/vite/", }, plugins: [ autoOrigin() ], publicDir: false, }); TYPO3-Anpassungen Simon Praetorius Vite & TYPO3
  10. public/_assets/vite/ ✦ .vite/manifest.json ✦ assets/ ✦ _Utils-edc17f93.js ✦ Main.entry-b51e57f8.js ✦

    Main.entry-47d11998.css Ergebnis Simon Praetorius Vite & TYPO3 vite build
  11. manifest.json Simon Praetorius Vite & TYPO3 "sitepackage/Resources/Private/Main.entry.js": { "css": [

    "assets/Main.entry-47d11998.css" ], "file": "assets/Main.entry-b51e57f8.js", "imports": [ "_Utils-edc17f93.js" ], "isEntry": true, "src": "sitepackage/Resources/Private/Main.entry.js" }, (generiert von vite)
  12. Best Practices Simon Praetorius Vite & TYPO3 import.meta.glob("../Components/**/*.{css,js}", {eager: true})

    import "JavaScript/Slider.js" import "Css/Main.css" import "Css/Main.scss" dedizierte Entrypoint-Datei(en): *.entry.js selektives Bundling: rekursives Bundling:
  13. Pfade & SCSS Simon Praetorius Vite & TYPO3 Bug bei

    relativen Pfaden in verschachtelten SCSS-Dateien github.com/vitejs/vite/issues/11012 Workarounds: 1) Pfade relativ zum Entrypoint definieren 2) resolve.alias in vite.config.js nutzen
  14. Fluid-Einbindung Simon Praetorius Vite & TYPO3 <vac:asset.vite entry="EXT:sitepackage/Resources/Private/Main.entry.js" /> Entrypoint

    (JS + CSS) einbinden: <link rel="preload" href="{vac:resource.vite( file: 'EXT:sitepackage/Resources/Private/Fonts/webfont.woff2' )}" ... /> Asset-URL extrahieren:
  15. YAML-Support Simon Praetorius Vite & TYPO3 editor: config: contentsCss: -

    "%vite('EXT:sitepackage/Resources/Private/Css/Rte.css')%" CSS für RTE einbinden: