remoteModulePlugin(cwd?: string): Plugin
esbuild plugin that lets a bundle reach modules served over HTTP, so
qunitx https://example.com/tests/cart-test.js runs the same way a local path does.
Three rules, which together are the whole of it:
- An absolute
http(s)specifier — an entry point, or an import inside any module — is claimed here. - Inside a remote module, a RELATIVE specifier resolves against the importing URL, which is
how a browser and every ES module loader already resolve one.
./helpers.jsbeside a remote test is the file beside it on that server. - Inside a remote module, anything else —
qunitx,lodash— resolves LOCALLY, against this project'snode_modules. A remote test importingqunitxmeans the runtime that is about to run it, not a package it hopes the server also happens to host.
Each module is fetched once per plugin instance, which is once per build. The cache lives here
rather than in the module so a --watch session gets fresh bytes on its next build instead of
serving a remote file that has since changed.
import { remoteModulePlugin } from './remote-module-plugin.ts'; remoteModulePlugin('/proj').name; // 'qunitx-remote-module'