{ "githubRoot": "https://github.com/nrwl/nx/blob/master", "name": "js", "description": "The Nx plugin that provides the best experience for developing JavaScript and TypeScript projects.", "root": "/packages/js", "source": "/packages/js/src", "documentation": [ { "name": "Overview", "id": "overview", "path": "/packages/js", "file": "shared/js-plugin", "content": "The JS plugin contains executors and generators that are useful for JavaScript/TypeScript projects in an Nx workspace.\n\n## Setting Up JS\n\n### Installation\n\nIn any Nx workspace, you can install `@nrwl/js` by running the following commands if `@nrwl/js` package is not installed:\n\n```shell\nnpm i --save-dev @nrwl/js\n```\n\n```shell\nyarn add --dev @nrwl/js\n```\n\n### `ts` Preset\n\nWhen initializing a new Nx workspace, specifying `--preset=ts` will generate a workspace with `@nrwl/js` pre-installed.\n\n```shell\nnpx create-nx-workspace my-org --preset=ts\n```\n\n```shell\nyarn create nx-workspace my-org --preset=ts\n```\n\n## Create Libraries\n\nYou can add a new JS/TS library with the following command:\n\n```shell\nnx g @nrwl/js:lib my-lib\n```\n\n## Build\n\nYou can `build` libraries that are generated with `--buildable` flag.\n\n```shell\nnx g @nrwl/js:lib my-buildable-lib --buildable\n```\n\nGenerating a library with `--buildable` will add a `build` target to the library's `project.json` file allows the library to be built.\n\n```shell\nnx build my-buildable-lib\n```\n\n## Test\n\nYou can test a library with the following command:\n\n```shell\nnx test my-lib\n```\n\n## Lint\n\nYou can lint a library with the following command:\n\n```shell\nnx lint my-lib\n```\n\n## Compiler\n\nBy default, `@nrwl/js` uses [TypeScript Compiler (TSC)](https://www.typescriptlang.org/docs/handbook/2/basic-types.html#tsc-the-typescript-compiler), via `@nrwl/js:tsc` executor, to compile your libraries. Optionally, you can switch `tsc` out for a different compiler with `--compiler` flag when executing the generators.\n\nCurrently, `@nrwl/js` supports the following compilers:\n\n- [Speedy Web Compiler (SWC)](https://swc.rs)\n\n### SWC\n\n- Create a buildable library with `swc`\n\n```shell\nnx g @nrwl/js:lib my-swc-lib --compiler=swc --buildable\n```\n\n- Convert a `tsc` library to use `swc`\n\n```shell\nnx g @nrwl/js:convert-to-swc my-buildable-lib\n```\n\nNow the `build` command will use `@nrwl/js:swc` executor to compile your libraries.\n\n> The first time you generate a `swc` library or convert a `tsc` library over to `swc`, `@nrwl/js` will install the necessary dependencies to use `swc`.\n" } ], "generators": [ { "name": "library", "factory": "./src/generators/library/library#libraryGenerator", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxTypescriptLibrary", "cli": "nx", "title": "Create a TypeScript Library", "description": "Create a TypeScript Library.", "type": "object", "examples": [ { "command": "nx g lib mylib --directory=myapp", "description": "Generate libs/myapp/mylib" } ], "properties": { "name": { "type": "string", "description": "Library name.", "$default": { "$source": "argv", "index": 0 }, "x-prompt": "What name would you like to use for the library?", "pattern": "^[a-zA-Z].*$" }, "directory": { "type": "string", "description": "A directory where the lib is placed." }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", "enum": ["eslint", "none"], "default": "eslint" }, "unitTestRunner": { "type": "string", "enum": ["jest", "none"], "description": "Test runner to use for unit tests.", "default": "jest" }, "tags": { "type": "string", "description": "Add tags to the library (used for linting)." }, "skipFormat": { "description": "Skip formatting files.", "type": "boolean", "default": false }, "skipTsConfig": { "type": "boolean", "description": "Do not update tsconfig.json for development experience.", "default": false }, "includeBabelRc": { "type": "boolean", "description": "Include a .babelrc configuration to compile TypeScript files" }, "testEnvironment": { "type": "string", "enum": ["jsdom", "node"], "description": "The test environment to use if unitTestRunner is set to jest.", "default": "jsdom" }, "importPath": { "type": "string", "description": "The library name used to import it, like @myorg/my-awesome-lib." }, "pascalCaseFiles": { "type": "boolean", "description": "Use pascal case file names.", "alias": "P", "default": false }, "js": { "type": "boolean", "description": "Generate JavaScript files rather than TypeScript files.", "default": false }, "strict": { "type": "boolean", "description": "Whether to enable tsconfig strict mode or not.", "default": true }, "publishable": { "type": "boolean", "default": false, "description": "Generate a publishable library." }, "buildable": { "type": "boolean", "default": true, "description": "Generate a buildable library." }, "setParserOptionsProject": { "type": "boolean", "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, "config": { "type": "string", "enum": ["workspace", "project", "npm-scripts"], "default": "project", "description": "Determines whether the project's executors should be configured in `workspace.json`, `project.json` or as npm scripts." }, "compiler": { "type": "string", "enum": ["tsc", "swc"], "default": "tsc", "description": "The compiler used by the build and test targets" }, "skipTypeCheck": { "type": "boolean", "description": "Whether to skip TypeScript type checking for SWC compiler.", "default": false } }, "required": ["name"], "presets": [] }, "aliases": ["lib"], "x-type": "library", "description": "Create a library", "implementation": "/packages/js/src/generators/library/library#libraryGenerator.ts", "hidden": false, "path": "/packages/js/src/generators/library/schema.json" }, { "name": "init", "factory": "./src/generators/init/init#initGenerator", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxTypescriptInit", "cli": "nx", "title": "Init nrwl/js", "description": "Init generator placeholder for nrwl/js.", "presets": [] }, "aliases": ["lib"], "x-type": "init", "description": "Init placeholder.", "implementation": "/packages/js/src/generators/init/init#initGenerator.ts", "hidden": false, "path": "/packages/js/src/generators/init/schema.json" }, { "name": "convert-to-swc", "factory": "./src/generators/convert-to-swc/convert-to-swc#convertToSwcGenerator", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxTypescriptLibrary", "cli": "nx", "title": "Convert a TSC library to SWC", "description": "Convert a TSC library to SWC.", "type": "object", "examples": [ { "command": "nx g swc mylib", "description": "Convert `libs/myapp/mylib` to SWC." } ], "properties": { "project": { "type": "string", "description": "Library name.", "$default": { "$source": "argv", "index": 0 }, "x-prompt": "What name would you like to use for the library?", "pattern": "^[a-zA-Z].*$" }, "targets": { "type": "array", "description": "List of targets to convert.", "items": { "type": "string", "description": "Target to convert." }, "default": ["build"] } }, "required": ["project"], "presets": [] }, "aliases": ["swc"], "x-type": "library", "description": "Convert a TypeScript library to compile with SWC.", "implementation": "/packages/js/src/generators/convert-to-swc/convert-to-swc#convertToSwcGenerator.ts", "hidden": false, "path": "/packages/js/src/generators/convert-to-swc/schema.json" } ], "executors": [ { "name": "tsc", "implementation": "/packages/js/src/executors/tsc/tsc.impl.ts", "schema": { "title": "Typescript Build Target", "description": "Builds using TypeScript.", "cli": "nx", "type": "object", "properties": { "main": { "type": "string", "description": "The name of the main entry-point file." }, "outputPath": { "type": "string", "description": "The output path of the generated files." }, "tsConfig": { "type": "string", "description": "The path to the Typescript configuration file." }, "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." }, "ignore": { "description": "An array of globs to ignore.", "type": "array", "items": { "type": "string" } }, "output": { "type": "string", "description": "Absolute path within the output." } }, "additionalProperties": false, "required": ["glob", "input", "output"] }, { "type": "string" } ] } }, "watch": { "type": "boolean", "description": "Enable re-building when files change.", "default": false }, "transformers": { "type": "array", "description": "List of TypeScript Transformer Plugins.", "default": [], "items": { "oneOf": [ { "type": "string" }, { "type": "object", "properties": { "name": { "type": "string" }, "options": { "type": "object", "additionalProperties": true } }, "additionalProperties": false, "required": ["name"] } ] } }, "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in `package.json`.", "default": true }, "buildableProjectDepsInPackageJsonType": { "type": "string", "description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.", "enum": ["dependencies", "peerDependencies"], "default": "peerDependencies" } }, "required": ["main", "outputPath", "tsConfig"], "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." }, "ignore": { "description": "An array of globs to ignore.", "type": "array", "items": { "type": "string" } }, "output": { "type": "string", "description": "Absolute path within the output." } }, "additionalProperties": false, "required": ["glob", "input", "output"] }, { "type": "string" } ] }, "transformerPattern": { "oneOf": [ { "type": "string" }, { "type": "object", "properties": { "name": { "type": "string" }, "options": { "type": "object", "additionalProperties": true } }, "additionalProperties": false, "required": ["name"] } ] } }, "presets": [] }, "description": "Build a project using TypeScript.", "aliases": [], "hidden": false, "path": "/packages/js/src/executors/tsc/schema.json" }, { "name": "swc", "implementation": "/packages/js/src/executors/swc/swc.impl.ts", "schema": { "$schema": "http://json-schema.org/schema", "cli": "nx", "title": "Typescript Build Target", "description": "Builds using SWC.", "type": "object", "properties": { "main": { "type": "string", "description": "The name of the main entry-point file." }, "outputPath": { "type": "string", "description": "The output path of the generated files." }, "tsConfig": { "type": "string", "description": "The path to the Typescript configuration file." }, "swcrc": { "type": "string", "description": "The path to the SWC configuration file. Default: .lib.swcrc" }, "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." }, "ignore": { "description": "An array of globs to ignore.", "type": "array", "items": { "type": "string" } }, "output": { "type": "string", "description": "Absolute path within the output." } }, "additionalProperties": false, "required": ["glob", "input", "output"] }, { "type": "string" } ] } }, "watch": { "type": "boolean", "description": "Enable re-building when files change.", "default": false }, "skipTypeCheck": { "type": "boolean", "description": "Whether to skip TypeScript type checking.", "default": false }, "swcExclude": { "type": "array", "description": "List of SWC Glob/Regex to be excluded from compilation (https://swc.rs/docs/configuration/compilation#exclude).", "default": [ "./src/**/.*.spec.ts$", "./**/.*.spec.ts$", "./src/**/jest-setup.ts$", "./**/jest-setup.ts$", "./**/.*.js$" ] }, "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in `package.json`.", "default": true }, "buildableProjectDepsInPackageJsonType": { "type": "string", "description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.", "enum": ["dependencies", "peerDependencies"], "default": "peerDependencies" } }, "required": ["main", "outputPath", "tsConfig"], "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." }, "ignore": { "description": "An array of globs to ignore.", "type": "array", "items": { "type": "string" } }, "output": { "type": "string", "description": "Absolute path within the output." } }, "additionalProperties": false, "required": ["glob", "input", "output"] }, { "type": "string" } ] } }, "presets": [] }, "description": "Build a project using SWC.", "aliases": [], "hidden": false, "path": "/packages/js/src/executors/swc/schema.json" } ] }