Which is the best structure for spliting code?

I’m on process to build a Figma plugin. But the problem that I could not import or export functions, constants variable from outside of file code.ts (this is root file of resource).

How can we split or separate a file to be a reusable methods, constants for ease-to-maintain?

In case, Figma required only one built-in file, should I use webpack to bundle to a single file? If yes, what kind of the best webpack that useful for solution? Thanks.

1 Like

Perhaps bundling with webpack can help you achieve the code splitting you’re looking for. Figma provides some good boilerplate that should get you started.

I like webpack, but I think the boilerplate with esbuild and Vite provided by Figma is better (they provided a better typescript structure with separation between the sandbox and iFrame).

1 Like

Interesting! I didn’t realize this was an option Figma provides. Will take a look into it, thanks!