Bundling Extensions For Directus
Directus v10
While bundling extensions for directus, you may want to use a module available in the used by the main directus module or maybe you want to keep the size of the extension build small. You can do so by declaring some dependency as external
.
You can do so with extension config file: extension.config.mjs
.
For e.g. If you want to use `sharp` which is included in the main directus module in your extension, you can do so with the following extension.config.mjs.
function externalPlugin(options = {}) { return { name: "external-plugin", options(inputOptions) { const externals = inputOptions.external; const customExternals = options.externals; inputOptions.external = Array.isArray(customExternals) ? [...externals, ...customExternals] : externals; } } } export default { plugins: [ externalPlugin({ externals: ["sharp"] }) ] }