From 9187be23459f60ab753f607f7550fcd6893e766c Mon Sep 17 00:00:00 2001 From: Sven Schwyn Date: Fri, 29 Nov 2024 12:48:21 +0100 Subject: [PATCH] Add an example for how to use assets via Node.js --- content/v2.2/assets/overview.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/content/v2.2/assets/overview.md b/content/v2.2/assets/overview.md index c4406e09..100f6167 100644 --- a/content/v2.2/assets/overview.md +++ b/content/v2.2/assets/overview.md @@ -157,6 +157,23 @@ public/assets Since `public/assets/login/app.js` is a bundle, it includes the content from the `app/assets/js/login/resetPassword.js` file it imported. +## Assets from Node.js + +To use a Node.js package such as Alpine.js, add it as a production dependency: + +```bash +npm install alpinejs +``` + +To bundle it, add the following to the entry point of your choice: + +```js +import Alpine from "alpinejs"; + +window.Alpine = Alpine; +Alpine.start(); +``` + ## Asset bundles The process of generating an asset bundle involves grouping multiple files (typically JavaScript or CSS) referenced from your entry point into single bundled file. This consolidation is helpful for web app performance, since it reduces the number of HTTP requests required to load a single page.