I'm building an XD plugin, can I require
addition files? Can I require files outside my plugin's directory?
Does XD support Node.js-style resolution?
Can I use lookup in a package.json
?
Yes. Note that require
file resolution does not align with Node.js-style resolution. You can only require files in your plugin directory, and there’s no lookup in a package.json
should it exist.
XD APIs are made available to your code using require:
const { Artboard } = require("scenegraph");
Or
const clipboard = require("clipboard");
The available XD APIs are listed in the XD plugin docs.
If you have a file called jquery.js
at the root level of your plugin, you can require it in like this:
const $ = require("./jquery");
Here's a sample plugin on the XD plugin samples GitHub repo that demonstrates this.
The XD plugin API docs have a page on JavaScript support that includes some of this information and more.