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 6.17.2 version of the framework. The framework was installed using the standard npm init adonisjs@latest <project-name> command. This setup used Inertia and Vue 3 for the frontend.
If you are using your own project structure or a different version, pay attention to the file paths and features of your version!
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/inertia/css/app.css.main.css@import "tailwindcss"; @import "preline/variants.css"; @source "../../node_modules/preline/dist/*.js"; /* Optional Preline UI Datepicker Plugin */ /* @import "preline/src/plugins/datepicker/styles.css"; */ /* Third-party plugins */ /* @plugin "@tailwindcss/forms"; */ /* Preline Themes */ @import "./themes/theme.css";See the Theme docs to learn more about Preline Themes.
-
Add type definitions for Preline
Create a
global.d.tsfile for the shared window typings, for exampleprojects_root_directory/inertia/types/global.d.ts.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 type { IStaticMethods } from 'preline/dist' 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: IStaticMethods } } export {} -
Reinitialize on component mount
Re-run Preline UI initialization from
projects_root_directory/inertia/plugins/preline.tswhenever mounted Vue components need it.preline.tsimport type { App } from 'vue' export default { install: (app: App) => { app.mixin({ async mounted() { await import('preline/dist') window.HSStaticMethods.autoInit() } }) } } -
Add Preline UI to the app entry
Import and attach the required external libraries in
projects_root_directory/inertia/app/app.ts, then register the Preline plugin.app.ts... import $ from 'jquery' import _ from 'lodash' import noUiSlider from 'nouislider' import 'datatables.net' import 'dropzone/dist/dropzone-min.js' import * as VanillaCalendarPro from 'vanilla-calendar-pro' window._ = _ window.$ = $ window.jQuery = $ window.DataTable = $.fn.dataTable window.noUiSlider = noUiSlider window.VanillaCalendarPro = VanillaCalendarPro window.Dropzone = window.Dropzone || {} import PrelinePlugin from '../plugins/preline' ... createInertiaApp({ .... setup({ el, App, props, plugin }) { createSSRApp({ render: () => h(App, props) }) .use(plugin) .use(PrelinePlugin) .mount(el) } })
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);