Plugins
Twelve libraries, each downloaded only on a page that uses it.
How loading works
src/js/core/plugins.jsNothing heavy is imported by app.js. A registry maps a
CSS selector to a dynamic import(), and only the entries
whose elements exist on the page are fetched. Each plugin module then
loads its library's browser build from vendors/ with
loadVendor(), so a library is downloaded only on the pages
that use it.
const REGISTRY = [
{ selector: '[data-chartjs]', load: () => import('../plugins/chartjs.js') },
{ selector: '[data-datatable]', load: () => import('../plugins/datatable.js') },
// …one line per plugin
];
A dashboard with no table never downloads Tabulator. SweetAlert2 goes one further and is not in the registry at all — it is imported in the half-second between somebody clicking a delete button and the dialog being needed.
The markers
Add the attribute, the library arrives| Marker | Loads | Reference |
|---|---|---|
data-chartjs="line" | Chart.js | Charts |
data-chart="radial" | ApexCharts | Charts |
data-datatable="invoices" | Tabulator | Datatable |
data-vectormap | jsVectorMap | Vector map |
data-datepicker | Flatpickr | Datepicker |
data-select | Tom Select | Advanced form |
data-editor | EasyMDE | Advanced form |
data-upload | Dropzone | Advanced form |
data-calendar | FullCalendar | Calendar |
data-sortable | SortableJS | Kanban |
data-confirm="…" | SweetAlert2, on click | Button |
pre code[class*="language-"] | Prism | These pages |
Adding your own
Install the library with npm, add it to the copyvendors
list in gulpfile.mjs and run npm run updateplugins.
Then write a module in src/js/plugins/ that exports
init(scope), and add one line to the registry.
// src/js/plugins/lightbox.js
import { qsa, loadVendor } from '../core/dom.js';
// Path inside vendors/, and the global the browser build defines.
const Lightbox = await loadVendor('some-lightbox/dist/lightbox.min.js', 'Lightbox');
export function init(scope = document) {
qsa('[data-lightbox]', scope).forEach((el) => {
if (el.dataset.lightboxBound === '1') return;
el.dataset.lightboxBound = '1';
new Lightbox(el);
});
}
The bound-flag guard matters: Brutalism.refresh(container)
runs the plugins again over newly injected markup, and without it a
modal filled from an API would initialise its widgets twice.
Plugin stylesheets
The one trap worth knowingA plugin stylesheet imported from JavaScript reaches the browser
after app.css and wins every tie on source order,
so the widget renders in its own light theme and your override does
nothing. Import it through a wrapper in
src/tailwindcss/vendors/ instead, and Gulp compiles it into
style.css:
@import 'flatpickr/dist/flatpickr.min.css' layer(vendor);
/* overrides, unlayered, below the import */
.flatpickr-day.selected {
@apply border-line bg-accent-300 text-ink;
}
Anything inside a cascade layer loses to unlayered rules whatever the
order. Never reach for !important here.