How to read html files from a plugin

In my plugin, I want to build a dialog containing custom HTML. The obvious course of action is to hard-code HTML in the same TypeScript file where I build the dialog but I want to see if I can make the HTML in a separate file and then read the contents of that file when needed. For example,

const html = await fs.readFile("utf-8", path.join(__dirname, "view.html"));

where fs is imported from fs native module or a library like fs-extra.

The problem is that the module path is a native module that cannot be bundled with a plugin. (here). Of course, I also cannot put the absolute path of the file.

So, what do I do ?

Maybe this would help?

1 Like

To get the path to you plugin directory you can use installationDir

const html = await fs.readFile("utf-8", path.join(await joplin.plugins.installationDir(), "view.html"));

I use many time the native module path in plugins.

import * as path from "path";
this.logFile = path.join(this.backupBasePath, "error.log");
1 Like