nx/docs/generated/packages/esbuild.json

313 lines
18 KiB
JSON

{
"githubRoot": "https://github.com/nrwl/nx/blob/master",
"name": "esbuild",
"packageName": "@nrwl/esbuild",
"description": "The Nx Plugin for esbuild contains executors and generators that support building applications using esbuild",
"root": "/packages/esbuild",
"source": "/packages/esbuild/src",
"documentation": [
{
"name": "Overview",
"id": "overview",
"path": "/packages/esbuild",
"file": "shared/esbuild-plugin",
"content": "The Nx Plugin for [esbuild](https://esbuild.github.io/api/), an extremely fast JavaScript bundler.\n\nWhy should you use this plugin?\n\n- _Fast_ builds using esbuild.\n- Type-checking using TypeScript, which esbuild does not handle.\n- Intelligent `package.json` output.\n- Additional [assets](/packages/esbuild/executors/esbuild#assets) for the output.\n\n## Setting up esbuild\n\nTo create a new workspace, run `npx create-nx-workspace@latest --preset=npm`.\n\nTo add the esbuild plugin to an existing workspace, run the following:\n\n{% tabs %}\n{% tab label=\"npm\" %}\n\n```shell\nnpm install -D @nrwl/esbuild\n```\n\n{% /tab %}\n{% tab label=\"yarn\" %}\n\n```shell\nyarn add -D @nrwl/esbuild\n```\n\n{% /tab %}\n{% /tabs %}\n\n### Creating a new JS library\n\nYou can add a new library that builds using esbuild with:\n\n```shell\nnx g @nrwl/js:lib mylib --bundler=esbuild\n```\n\nThis command will install the esbuild plugin if needed, and set `@nrwl/esbuild:esbuild` executor for the `build` target.\n\n### Adding esbuild target to existing libraries\n\nIf you already have a JS project that you want to use esbuild for, run this command:\n\n```shell\nnx g esbuild-project mylib\n```\n\nThis generator validates there isn't an existing `build` target. If you want to overwrite the existing target you can pass the `--skipValidation` option.\n\n```shell\nnx g esbuild-project mylib --skipValidation\n```\n\n## Using esbuild\n\nYou can run builds with:\n\n```shell\nnx build mylib\n```\n\nReplace `mylib` with the name or your project. This command works for both applications and libraries.\n\n### Copying assets\n\nAssets are non-JS and non-TS files, such as images, CSS, etc. You can add them to the project configuration as follows.\n\n```jsonc\n\"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n //...\n \"assets\": [\n { \"input\": \"libs/mylib\", \"glob\": \"README.md\", \"output\": \"/\" },\n { \"input\": \"libs/mylib\", \"glob\": \"logo.png\", \"output\": \"/\" },\n { \"input\": \"libs/mylib\", \"glob\": \"docs/**/*.md\", \"output\": \"/docs\" },\n //...\n ]\n }\n}\n```\n\nRunning `nx build mylib` outputs something like this.\n\n```text\ndist/libs/mylib/\n├── README.md\n├── docs\n│ ├── CONTRIBUTING.md\n│ └── TESTING.md\n├── index.js\n├── logo.png\n└── package.json\n```\n\n### Generating a metafile\n\nA metafile can be generated by passing the `--metafile` option. This file contains information about the build that can be analyzed by other tools, such as [bundle buddy](https://www.bundle-buddy.com/esbuild).\n\n```shell\nnx build mylib --metafile\n```\n\nThis command will generate a `meta.json` file in the output directory.\n\n```text\ndist/libs/mylib/\n├── README.md\n├── index.js\n├── meta.json\n└── package.json\n```\n\n### Custom esbuild options\n\nExtra API options for esbuild can be passed in the `esbuildOptions` object for your project configuration.\n\n```jsonc\n\"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n //...\n \"esbuildOptions\": {\n \"banner\": { \".js\": \"// banner\" },\n \"footer\": { \".js\": \"// footer\" }\n }\n }\n}\n```\n\n## More Documentation\n\n- [Using JS](/packages/js)\n"
}
],
"generators": [
{
"name": "init",
"factory": "./src/generators/init/init#esbuildInitGenerator",
"schema": {
"$schema": "http://json-schema.org/schema",
"$id": "NxWebpackInit",
"cli": "nx",
"title": "Init Webpack Plugin",
"description": "Init Webpack Plugin.",
"type": "object",
"properties": {
"compiler": {
"type": "string",
"enum": ["babel", "swc", "tsc"],
"description": "The compiler to initialize for.",
"default": "babel"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
}
},
"required": [],
"presets": []
},
"description": "Initialize the `@nrwl/esbuild` plugin.",
"aliases": ["ng-add"],
"hidden": true,
"implementation": "/packages/esbuild/src/generators/init/init#esbuildInitGenerator.ts",
"path": "/packages/esbuild/src/generators/init/schema.json"
},
{
"name": "esbuild-project",
"factory": "./src/generators/esbuild-project/esbuild-project#esbuildProjectGenerator",
"schema": {
"$schema": "http://json-schema.org/schema",
"$id": "NxEsBuildProject",
"cli": "nx",
"title": "Add esbuild configuration to a project",
"description": "Add esbuild configuration to a project.",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "The name of the project.",
"$default": { "$source": "argv", "index": 0 },
"x-dropdown": "project",
"x-prompt": "What is the name of the project to set up a esbuild for?"
},
"main": {
"type": "string",
"description": "Path relative to the workspace root for the main entry file. Defaults to `<project-root>/src/main.ts` or `<project-root>src/index.ts`, whichever is found.",
"alias": "entryFile"
},
"tsConfig": {
"type": "string",
"description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to `<project-root>/tsconfig.app.json` or `<project-root>/tsconfig.lib.json`, whichever is found."
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`."
},
"skipValidation": {
"type": "boolean",
"default": false,
"description": "Do not perform any validation on existing project."
},
"importPath": {
"type": "string",
"description": "The library name used to import it, like `@myorg/my-awesome-lib`."
},
"platform": {
"type": "string",
"description": "Platform target for outputs.",
"enum": ["browser", "node", "neutral"],
"default": "node"
}
},
"required": [],
"examplesFile": "```bash\nnx g @nrwl/esbuild:esbuild-project my-package\n```\n\n{% callout type=\"note\" title=\"Overwriting existing build option\" %}\nThe `esbuild-projet` generator validates that an existing `build` target isn't already defined for the project. If you are adding esbuild to a project with an existing `build` target, pass the `--skipValidation` option.\n{% /callout %}\n\nYou may also provide a custom main entry file, or a custom tsconfig file if the defaults don't work. By default, the generator will look for a main file matching `src/index.ts` or `src/main.ts`, and a tsconfig file matching `tsconfig.app.json` or `tsconfig.lib.json`.\n\n```bash\nnx g @nrwl/esbuild:esbuild-project my-package \\\n--main=packages/my-package/src/entry.ts \\\n--tsConfig=packages/my-package/tsconfig.custom.json\n```\n",
"presets": []
},
"description": "Add esbuild configuration to a project.",
"hidden": true,
"implementation": "/packages/esbuild/src/generators/esbuild-project/esbuild-project#esbuildProjectGenerator.ts",
"aliases": [],
"path": "/packages/esbuild/src/generators/esbuild-project/schema.json"
}
],
"executors": [
{
"name": "esbuild",
"implementation": "/packages/esbuild/src/executors/esbuild/esbuild.impl.ts",
"schema": {
"version": 2,
"outputCapture": "direct-nodejs",
"title": "esbuild (experimental)",
"description": "Bundle a package for different platforms. Note: declaration (*.d.ts) file are not currently generated.",
"cli": "nx",
"type": "object",
"properties": {
"main": {
"type": "string",
"description": "The path to the entry file, relative to project.",
"alias": "entryFile",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.js|.ts)"
},
"outputPath": {
"type": "string",
"description": "The output path of the generated files.",
"x-completion-type": "directory"
},
"outputFileName": {
"type": "string",
"description": "Name of the main output file. Defaults same basename as 'main' file."
},
"tsConfig": {
"type": "string",
"description": "The path to tsconfig file.",
"x-completion-type": "file",
"x-completion-glob": "tsconfig.*.json"
},
"project": {
"type": "string",
"description": "The path to package.json file."
},
"additionalEntryPoints": {
"type": "array",
"description": "List of additional entry points.",
"items": { "type": "string" },
"default": []
},
"format": {
"type": "array",
"description": "List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).",
"alias": "f",
"items": { "type": "string", "enum": ["esm", "cjs"] },
"default": ["esm"]
},
"watch": {
"type": "boolean",
"description": "Enable re-building when files change.",
"default": false
},
"assets": {
"type": "array",
"description": "List of static assets.",
"default": [],
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"glob": {
"type": "string",
"description": "The pattern to match."
},
"input": {
"type": "string",
"description": "The input directory path in which to apply `glob`. Defaults to the project root."
},
"output": {
"type": "string",
"description": "Relative path within the output folder."
},
"ignore": {
"description": "An array of globs to ignore.",
"type": "array",
"items": { "type": "string" }
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
},
{ "type": "string" }
]
}
},
"deleteOutputPath": {
"type": "boolean",
"description": "Remove previous output before build.",
"alias": "clean",
"default": true
},
"external": {
"type": "array",
"description": "Mark one or more module as external. Can use * wildcards, such as '*.png'.",
"items": { "type": "string" }
},
"outputHashing": {
"type": "string",
"description": "Define the output filename cache-busting hashing mode.",
"default": "none",
"enum": ["none", "all"]
},
"metafile": {
"type": "boolean",
"description": "Generate a meta.json file in the output folder that includes metadata about the build. This file can be analyzed by other tools.",
"default": false
},
"sourcemap": {
"type": "boolean",
"alias": "sourceMap",
"description": "Generate sourcemap.",
"default": false
},
"minify": {
"type": "boolean",
"description": "Minifies outputs.",
"default": false
},
"platform": {
"type": "string",
"description": "Platform target for outputs.",
"enum": ["browser", "node", "neutral"],
"default": "node"
},
"target": {
"type": "string",
"description": "The environment target for outputs.",
"default": "esnext"
},
"skipTypeCheck": {
"type": "boolean",
"description": "Skip type-checking via TypeScript. Skipping type-checking speeds up the build but type errors are not caught.",
"default": false
},
"thirdParty": {
"type": "boolean",
"description": "Includes third-party packages in the bundle (i.e. npm packages).",
"default": true
},
"dependenciesFieldType": {
"type": "string",
"description": "When `bundleInternalProjectsOnly` is true, this option determines whether external packages should be in 'dependencies' or 'peerDependencies' field in the generated package.json file.",
"enum": ["dependencies", "peerDependencies"],
"default": "dependencies"
},
"esbuildOptions": {
"type": "object",
"description": "Additional options to pass to esbuild. See https://esbuild.github.io/api/.",
"additionalProperties": true
}
},
"required": ["tsConfig", "main", "outputPath"],
"definitions": {
"assetPattern": {
"oneOf": [
{
"type": "object",
"properties": {
"glob": {
"type": "string",
"description": "The pattern to match."
},
"input": {
"type": "string",
"description": "The input directory path in which to apply `glob`. Defaults to the project root."
},
"output": {
"type": "string",
"description": "Relative path within the output folder."
},
"ignore": {
"description": "An array of globs to ignore.",
"type": "array",
"items": { "type": "string" }
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
},
{ "type": "string" }
]
}
},
"additionalProperties": true,
"examplesFile": "`<app-root>/project.json`:\n\n```json\n{\n //...\n \"targets\": {\n //...\n \"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n \"main\": \"<app-root>\",\n \"tsConfig\": \"<app-root>/tsconfig.app.json\",\n \"outputPath\": \"dist/<app-root>\"\n }\n }\n }\n}\n```\n\n```bash\nnx build <app-name>\n```\n\n## Examples\n\n{% tabs %}\n{% tab label=\"CommonJS output\" %}\n\nThe CommonJS format is required in some environments, such as Electron applications. By default, `esbuild` will use the ESM format, which is recommended for Web and Node applications. You may also output to multiple formats.\n\n```bash\nnx build <app-name> --format=cjs\nnx build <app-name> --format=esm,cjs\nnx build <app-name> # defaults to es# defaults to esm\n```\n\n```json\n\"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n \"main\": \"<app-root>\",\n \"tsConfig\": \"<app-root>/tsconfig.app.json\",\n \"outputPath\": \"dist/<app-root>\",\n \"format\": [\"esm\", \"cjs\"]\n}\n```\n\n{% /tab %}\n{% tab label=\"External packages\" %}\n\nYou can avoid packages from being bundled by providing the `external` option with a list of packages to skip.\n\nYou can also use `*` wildcard to match assets.\n\n```json\n\"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n \"main\": \"<app-root>\",\n \"tsConfig\": \"<app-root>/tsconfig.app.json\",\n \"outputPath\": \"dist/<app-root>\",\n \"external\": [\"lodash\", \"*.png\"]\n}\n```\n\n{% /tab %}\n{% tab label=\"Skip type checking\" %}\n\nType checking is the slowest part of the build. You may want to skip type checking during build and run it as another job in CI.\n\n```json\n\"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n \"main\": \"<app-root>\",\n \"tsConfig\": \"<app-root>/tsconfig.app.json\",\n \"outputPath\": \"dist/<app-root>\",\n \"skipTypeCheck\": true\n}\n```\n\n{% /tab %}\n{% tab label=\"Additional esbuild options\" %}\n\nAdditional [esbuild options](https://esbuild.github.io/api/) can be passed using `esbuildOptions` in your project configuration.\n\n```json\n\"build\": {\n \"executor\": \"@nrwl/esbuild:esbuild\",\n \"options\": {\n \"main\": \"<app-root>\",\n \"tsConfig\": \"<app-root>/tsconfig.app.json\",\n \"outputPath\": \"dist/<app-root>\",\n \"esbuildOptions\": {\n \"legalComments\": \"inline\"\n \"banner\": {\n \".js\": \"// banner\"\n },\n \"footer\": {\n \".js\": \"// footer\"\n }\n }\n}\n```\n\n{% /tab %}\n{% tabs %}\n",
"presets": []
},
"description": "Bundle a package using EsBuild.",
"aliases": [],
"hidden": false,
"path": "/packages/esbuild/src/executors/esbuild/schema.json"
}
]
}