* Update the minimal theme * Remove unused files * Remove unused default dark theme * Fix type error * Fix the order of themes in the picker interface * Fix account/sign-out not using module foreground color * Fix module bar interface styling * Update system match label * Use half width for default appearance * Fix preview changed based on appearance * Add includeNull option to theme selector interface * Add minimal theme extension docs * Attempt to make typedoc play nice * Remove module bar color override * Add snippet on overrides interface * Deprecate "normal" style v-notice * System filter interface background * Add menu scope * Use colors consistent with interface previews * Remove card-face-color usage * Use consistent hover style in collections & fields * Deprecate card-face-color * Remove old --card vars * Fix revisions divider styling * Remove duplicate background from overview header * Fix permissions overview corner overlap * Make form input height configurable * Allow overriding public form input height * Rename text string * updated data model icon * Standardize form settings between scopes * Allow overriding sidebar forms * Add configurable form gap * Add configurable input-padding * Fix list-item padding * Fix padding in block style * Add links to defaults * Apply color match updates * Default to database icon * Fix schaling of theme selector interface * Fix font loading * Fetch font weights from Google as well * Use display weight in titles * Fix color match display font * Clean up font weights for labels * Update test to remove normal state * Remove typo * Add lowercase dev * Add changeset * Remove font-weight --------- Co-authored-by: Ben Haynes <ben@rngr.org>
4.1 KiB
description, readTime, contributors
| description | readTime | contributors |
|---|---|---|
| A guide on how to scaffold your Directus Extension. | 5 min read | Rijk Van Zanten, Esther Agbaje |
Creating Extensions
To create an extension, use the create-directus-extension utility:
npx create-directus-extension@latest
After specifying the name of the extension, the type of the extension and the programming language you want to use, the utility will create a folder with the recommended file structure to create an extension.
If you want to combine and share dependencies between one or more extensions, use the bundle extension type.
Building Your Extension
Before your extension can be used by Directus, it has to be built. If you used the create-directus-extension utility
to scaffold your extension, building your extension is as easy as running:
npm run build
The generated package.json contains a script that calls the directus-extension CLI which is part of
@directus/extensions-sdk:
{
"scripts": {
"build": "directus-extension build"
}
}
If you prefer to scaffold your extension manually, you can use the directus-extension CLI binary directly. The
--help flag provides useful information regarding the available options and flags.
Internally, the CLI uses Rollup to bundle your extension to a single entrypoint.
::: tip Watch
The CLI supports rebuilding extensions whenever a file has changed by using the --watch flag.
:::
Configuring the CLI
Most of the time, it should be sufficient to use the CLI as is. But, in some cases it might be necessary to customize it
to your specific needs. This can be done by creating a extension.config.js file at the root of your extension package
with the following content:
export default {
plugins: [],
};
Supported Options
plugins— An array of Rollup plugins that will be used when building extensions in addition to the built-in ones.
::: tip CommonJS or ESM
By using the type field inside your package.json file or using the appropriate file extension (.mjs or .cjs),
the config file can be loaded as a CommonJS or ESM file.
:::
::: tip Component Library
Directus comes shipped with it's own Vue Component Library and Storybook that you can use to enrich your extensions. These components can be used in any of the "app extensions", including Interfaces, Displays, Modules, Layouts, and Panels.
:::
Extension Folder Structure
The folder created by the utility is in fact an npm package. It comes with a few pre-installed packages depending on the
extension type and the programming language you chose. The most important one is @directus/extensions-sdk. This
package includes a CLI, which allows you to build your extension and to scaffold additional extensions, Typescript
helpers, and other utilities.
Inside the created folder there is a src/ folder. This folder contains the entrypoint of your extension. If you write
additional source files, they should go into this folder.
::: tip Entrypoint
The entrypoint is either called index.js or index.ts, depending on which programming language you chose.
:::
The generated package.json file contains an additional directus:extension field with the following sub-fields:
type— The type of the extensionpath— The path to the built extensionsource— The path to the source entrypointhost— A semver string that indicates with which versions of the Directus host, the extension is compatible with
The CLI will use those fields by default to determine the input and output file paths and how the extension should be built.
Developing Your Extension
To learn more about how to develop extensions of a specific type, refer to the individual guides: