esbuild plugin that enables seamless integration of the Perspective data visualization library into applications bundled with esbuild
npx @tessl/cli install tessl/npm-finos--perspective-esbuild-plugin@3.2.0The Perspective esbuild Plugin enables seamless integration of the Perspective data visualization library into applications bundled with esbuild. It handles WebAssembly (WASM) module loading, web worker integration, and provides specialized build configurations required by Perspective's high-performance analytics engine.
npm install @finos/perspective-esbuild-pluginconst { PerspectiveEsbuildPlugin } = require("@finos/perspective-esbuild-plugin");For ES modules:
import { PerspectiveEsbuildPlugin } from "@finos/perspective-esbuild-plugin";const esbuild = require("esbuild");
const { PerspectiveEsbuildPlugin } = require("@finos/perspective-esbuild-plugin");
esbuild.build({
entryPoints: ["src/index.js"],
plugins: [PerspectiveEsbuildPlugin()],
format: "esm",
bundle: true,
loader: {
".ttf": "file",
},
});When using this plugin, you must:
format: "esm" option in your esbuild configurationtype="module" attribute in your app's <script> tag@finos/perspective/dist/esm/perspective.js and @finos/perspective-viewer/dist/esm/perspective-viewer.jsThe plugin is composed of several specialized internal sub-plugins that work together:
PerspectiveEsbuildPlugin orchestrates the WASM and Worker pluginsPrimary plugin factory that creates an esbuild plugin combining WASM and Worker functionality.
function PerspectiveEsbuildPlugin(options?: PluginOptions): EsbuildPlugin;
interface PluginOptions {
wasm?: {
inline?: boolean; // Whether to inline WASM files as binary data
webpack_hack?: boolean; // Disable webpack URL compatibility mode (default: false, meaning webpack compatibility enabled)
};
worker?: {
targetdir?: string; // Worker output directory (default: "build/worker")
};
}
interface EsbuildPlugin {
name: string;
setup: (build: PluginBuild) => void;
}Handles web worker bundling with automatic fallback to single-threaded mode when workers are not available.
format: "esm") buildstype="module" for script tags