Plugin JavaScript Initialization Order

I’m working on a TW plugin that uses some existing JS libraries. I want to understand plugin initialization order better:

  1. I have a plugin ($:/plugins/peter/library) that exposes a JS library as a TW plugin. I added if ($tw.browser) { ... } to the JS source to avoid initializing the plugin (which requires window and friends) when running from node
  2. I have another plugin ($:/plugins/peter/something) that has a dependents field set to `$:/plugins/peter/library
  3. I add console.log statements to both plugins

I noticed that $:/plugins/peter/library has its log statements run after $:/plugins/peter/library. This is surprising - shouldn’t the “leaf-most” plugin get initialized first?

The dependents field is only used during plugin installation from a plugin library.

Give your library tiddler, the value library for the field module-type. Then in the module in the plugin require the library using the tiddler title. Make sure it exports what you need to access to.

mylib = require(“library-tiddler.title”);

1 Like

Thanks, Saq - that was it! I’m able to use this now.

1 Like