Install Preline UI with Adonis using Tailwind CSS
Install Preline UI with Tailwind CSS in AdonisJS projects, including JavaScript plugin setup, AdonisJS configuration, app styles, and optional dependencies.
Installation
Please note that the plugin has been tested with the 7.3 version of the framework. The framework was installed using the standard npm init adonisjs@latest <project-name> command with the web starter kit, which renders views with the Edge templating engine and bundles frontend assets with Vite, with no Inertia or client-side framework involved.
If you are using the inertia starter kit or a different version, pay attention to the file paths and features of your setup!
Adonis quick setup
If Tailwind CSS is not set up yet, start with the official AdonisJS + Tailwind CSS guide first.
Some components rely on third-party libraries. The setup below assumes full Preline UI usage with those dependencies preloaded. If you do not plan to use those components, you can remove the related libraries from your configuration.
-
Install Preline UI
Install
prelinewith your preferred package manager.Terminalnpm install prelinePreline UI uses the Tailwind CSS Forms plugin across form components. Install it if you have not already:
npm install -D @tailwindcss/forms -
Include Preline CSS
Import Preline into
projects_root_directory/resources/css/app.css, the CSS entrypoint thewebstarter kit already wires into Vite. Also point@sourceat your own view templates. Edge templates are scanned automatically as long as they are not excluded by.gitignore, but declaring the path explicitly keeps class detection reliable regardless of where your.edgefiles live.app.css@import "tailwindcss"; @import "preline/variants.css"; @source "../../node_modules/preline/dist/*.js"; @source "../views"; /* Optional Preline UI Datepicker Plugin */ /* @import "preline/datepicker-styles-utility.css"; */ /* Plugins */ /* @plugin "@tailwindcss/forms"; */ /* Preline Themes */ @import "preline/theme.css"; /* Optional Preline UI Datatable Plugin: DataTables.net renders its own search/length/paging controls alongside Preline's own; hide the native ones since they can't be disabled through DataTables options alone. */ /* .dt-layout-row:has(.dt-search), .dt-layout-row:has(.dt-length), .dt-layout-row:has(.dt-paging) { display: none !important; } */See the Theme docs to learn more about Preline Themes.
-
Add type definitions for Preline
If your Vite entrypoint is TypeScript, create a
global.d.tsfile for the shared window typings, for exampleprojects_root_directory/resources/js/global.d.ts. Skip this step ifresources/js/app.jsstays plain JavaScript, which is what thewebstarter kit ships by default.global.d.tsimport { JQueryStatic } from 'jquery' import type { DataTable } from 'datatables.net' import type { Dropzone } from 'dropzone' import noUiSlider from 'nouislider' import * as VanillaCalendarPro from 'vanilla-calendar-pro' import { HSStaticMethods } from 'preline/non-auto' declare global { interface Window { // Optional third-party libraries _: typeof import('lodash') $: JQueryStatic jQuery: JQueryStatic DataTable: typeof DataTable Dropzone: typeof Dropzone noUiSlider: typeof noUiSlider VanillaCalendarPro: typeof VanillaCalendarPro // Preline UI HSStaticMethods: typeof HSStaticMethods } } export {} -
Load the entrypoint from your layout
Edge templates only render HTML on the server, so the script that initializes Preline UI has to ship from the Vite entrypoint your shared layout loads with the
@@vitetag, for example inprojects_root_directory/resources/views/components/layout.edge.layout.edge<head> ... @@vite(['resources/css/app.css', 'resources/js/app.js']) </head>Edge navigation is a full page load, unlike Inertia or an SPA, so there is no client-side router or DOM diffing to account for. A single
autoInitcall that runs once the DOM is ready is enough, since there is no per-navigation or per-component re-init step to write. -
Add Preline UI to the app entry
Expose any optional third-party dependencies on
windowfrom their own module, imported beforeprelineitself, then callautoInitonce the DOM is ready. The separate module matters: within a single file, ES modules evaluate all of that file's own static imports as one batch before any of the file's own top-level statements run, so assigningwindow.jQuery = jQueryand importingprelinein the same file does not reliably run the assignment first.resources/js/vendor-globals.jsimport jQuery from 'jquery' import DataTable from 'datatables.net' import _ from 'lodash' import * as VanillaCalendarPro from 'vanilla-calendar-pro' import noUiSlider from 'nouislider' import Dropzone from 'dropzone' window.jQuery = jQuery window.$ = jQuery window.DataTable = DataTable window._ = _ window.VanillaCalendarPro = VanillaCalendarPro window.noUiSlider = noUiSlider window.Dropzone = Dropzoneresources/js/app.jsimport './vendor-globals.js' import { HSStaticMethods } from 'preline/non-auto' document.addEventListener('DOMContentLoaded', () => { HSStaticMethods.autoInit() })preline/non-autois the better entry here because initialization is handled explicitly. The defaultprelineentry registers per-pluginwindowload listeners, whilepreline/non-autodoes not. Pairing the non-auto entry with the explicitDOMContentLoadedcall keeps initialization timing under the application's control and avoids a second automatic initialization path.
Optional Preline UI styles
Preline UI ships with a small set of opinionated base styles. If you want them in your project, add them to your CSS file. These defaults used to come bundled with Tailwind CSS v3, so they are still available as an optional layer in Preline UI.
/* Adds pointer cursor to buttons */
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}
/* Defaults hover styles on all devices */
@custom-variant hover (&:hover);
Specific guide
Continue with a focused guide for wiring Preline UI JavaScript plugins into this framework.