# build-plugin **Repository Path**: mirrors_DataDog/build-plugin ## Basic Information - **Project Name**: build-plugin - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-26 - **Last Updated**: 2023-08-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Datadog Build Plugins A set of bundler plugins for: - [ESBuild esbuild `@datadog/esbuild-plugin`](/packages/published/esbuild-plugin#readme) - [Rollup Rollup `@datadog/rollup-plugin`](/packages/published/rollup-plugin#readme) - [Rspack Rspack `@datadog/rspack-plugin`](/packages/published/rspack-plugin#readme) - [Vite Vite `@datadog/vite-plugin`](/packages/published/vite-plugin#readme) - [Webpack Webpack `@datadog/webpack-plugin`](/packages/published/webpack-plugin#readme) To interact with Datadog directly from your builds. > [!NOTE] > If you want to upgrade from v1 to v2, please follow our [migration guide](/MIGRATIONS.md#v1-to-v2). ## Table of content - [Installation](#installation) - [Usage](#usage) - [Configuration](#configuration) - [`auth.apiKey`](#authapikey) - [`auth.appKey`](#authappkey) - [`customPlugins`](#customplugins) - [`disableGit`](#disablegit) - [`logLevel`](#loglevel) - [`metadata.name`](#metadataname) - [Features](#features) - [Error Tracking](#error-tracking-----) - [Telemetry](#telemetry-----) - [Contributing](#contributing) - [License](#license) ## Installation - Yarn ```bash yarn add -D @datadog/{{bundler}}-plugin ``` - npm ```bash npm install --save-dev @datadog/{{bundler}}-plugin ``` ## Usage In your bundler's configuration file: ```js const { datadog{{Bundler}}Plugin } = require('@datadog/{{bundler}}-plugin'); export const config = { plugins: [ datadog{{Bundler}}Plugin({ // Configuration }), ], }; ``` > [!TIP] > It is best to have the plugin in the first position in order to report every other plugins. Follow the specific documentation for each bundler: - [ESBuild esbuild `@datadog/esbuild-plugin`](/packages/published/esbuild-plugin#readme) - [Rollup Rollup `@datadog/rollup-plugin`](/packages/published/rollup-plugin#readme) - [Rspack Rspack `@datadog/rspack-plugin`](/packages/published/rspack-plugin#readme) - [Vite Vite `@datadog/vite-plugin`](/packages/published/vite-plugin#readme) - [Webpack Webpack `@datadog/webpack-plugin`](/packages/published/webpack-plugin#readme) ## Configuration
Full configuration object ```typescript { auth?: { apiKey?: string; }; customPlugins?: (arg: GetPluginsArg) => UnpluginPlugin[]; logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none'; errorTracking?: { disabled?: boolean; sourcemaps?: { bailOnError?: boolean; disableGit?: boolean; dryRun?: boolean; intakeUrl?: string; maxConcurrency?: number; minifiedPathPrefix: string; releaseVersion: string; service: string; }; }; telemetry?: { disabled?: boolean; enableTracing?: boolean; endPoint?: string; output?: boolean | string | { destination: string; timings?: boolean; metrics?: boolean; }; prefix?: string; tags?: string[]; timestamp?: number; filters?: ((metric: Metric) => Metric | null)[]; }; } ```
### `auth.apiKey` > default `null` In order to interact with Datadog, you have to use [your own API Key](https://app.datadoghq.com/organization-settings/api-keys). ### `auth.appKey` > default `null` In order to interact with Datadog, you have to use [your own Application Key](https://app.datadoghq.com/organization-settings/application-keys). ### `customPlugins` > default: `[]` This is a way for you to inject any [Unplugin Plugin](https://unplugin.unjs.io/guide/) you want. It's particularly useful to use our [global, shared context](/packages/factory/README.md#global-context) of the main plugin. And to prototype some new plugins in the same environment. ```typescript { customPlugins: ({ options, context }) => { const name = 'my-custom-plugin'; const log = context.getLogger(name); return [{ name, buildStart() { log.info('Hello world'); }, }] }; } ``` Your function will receive three arguments: - `options`: The options you passed to the main plugin (including your custom plugins). - `context`: The global context shared accross our plugin. - `bundler`: The currently running bundler's instance. The `context` is a shared object that is mutated during the build process. Your function has to return an array of [Unplugin Plugins definitions](https://unplugin.unjs.io/guide/#supported-hooks).
You can also use our own [custom hooks](/packages/plugins/custom-hooks#existing-hooks).
Full context object
type GlobalContext = {
    // Trigger an asynchronous custom hook.
    asyncHook: async (name: string, ...args: any[]) => Promise;
    // Mirror of the user's config.
    auth?: {
        apiKey?: string;
        appKey?: string;
    };
    // Available in the `buildReport` hook.
    build: BuildReport;
    // Available in the `bundlerReport` hook.
    bundler: BundlerReport;
    cwd: string;
    env: string;
    getLogger: (name: string) => Logger;
    // Available in the `git` hook.
    git?: Git;
    // Trigger a synchronous custom hook.
    hook: (name: string, ...args: any[]) => void;
    inject: Injection;
    // The list of all the plugin names that are currently running in the ecosystem.
    pluginNames: string[];
    // The list of all the plugin instances that are currently running in the ecosystem.
    plugins: Plugin[];
    // Send a log to Datadog.
    sendLog: (message: string, context?: Record) => Promise;
    // The start time of the build.
    start: number;
    // The version of the plugin.
    version: string;
}
#### [📝 Full documentation ➡️](/packages/factory#global-context) ### `disableGit` > default: `false` Disable the [Git plugin](/packages/plugins/git#readme) if you don't want to use it.
For instance if you see a `Error: No git remotes available` error. ### `logLevel` > default: `'warn'` Which level of log do you want to show. ### `metadata.name` > default: `null` The name of the build.
This is used to identify the build in logs, metrics and spans. ## Features ### Error Tracking ESBuild Rollup Rspack Vite Webpack > Interact with Error Tracking directly from your build system. #### [📝 Full documentation ➡️](/packages/plugins/error-tracking#readme)
Configuration ```typescript datadogWebpackPlugin({ errorTracking?: { disabled?: boolean, sourcemaps?: { bailOnError?: boolean, disableGit?: boolean, dryRun?: boolean, intakeUrl?: string, maxConcurrency?: number, minifiedPathPrefix: string, releaseVersion: string, service: string, }, } }); ```
### Telemetry ESBuild Rollup Rspack Vite Webpack > Display and send telemetry data as metrics to Datadog. #### [📝 Full documentation ➡️](/packages/plugins/telemetry#readme)
Configuration ```typescript datadogWebpackPlugin({ telemetry?: { disabled?: boolean, enableTracing?: boolean, endPoint?: string, output?: boolean | string | { destination: string, timings?: boolean, metrics?: boolean, }, prefix?: string, tags?: string[], timestamp?: number, filters?: ((metric: Metric) => Metric | null)[], } }); ```
## Contributing Check out [CONTRIBUTING.md](/CONTRIBUTING.md) for more information about how to work with the build-plugins ecosystem. ## License [MIT](/LICENSE) ### [Back to top :arrow_up:](#top)