ctx.resolve(name, { mode }?)

Loads a module from a _private/ folder. The lookup starts at the route's folder (the page being served), wherever ctx.resolve is called from, so a layout or partial gets the same answer as the page: _private/ in the route's folder, then each parent folder up to pb_pages/. A name starting with / looks only in pb_pages/_private/. Without an extension, the name, then .js, .ts and .json are tried.

// pb_pages/_private/shout.ts
module.exports = (s) => String(s).toUpperCase()
<p><%= ctx.resolve('shout')('hi') %></p>  <!-- HI -->

Modes

Mode Returns
require (default) The module's exports
raw The file's text
script The text wrapped in <script>
style The text wrapped in <style>
<head>
  <%- ctx.resolve('theme.css', { mode: 'style' }) %>
  <%- ctx.resolve('widgets.js', { mode: 'script' }) %>
</head>

Modules from node_modules

Page code can also require() by name: _private/ folders first (nearest to the file calling require), then packages from pb_pages/node_modules, then the app's usual module paths. See JavaScript Runtime.