diff --git a/docs/generated/packages/nx-plugin.json b/docs/generated/packages/nx-plugin.json index 427d7ed292..838ba56845 100644 --- a/docs/generated/packages/nx-plugin.json +++ b/docs/generated/packages/nx-plugin.json @@ -10,7 +10,7 @@ "name": "Overview", "path": "/packages/nx-plugin", "file": "shared/nx-plugin", - "content": "Nx plugins are npm packages that contain generators and executors to extend a Nx workspace. Generators are blueprints to create new files from templates, and executors run those files. These plugins also update the `nx.json` when generating new libs or apps.\n\n> A list of plugins that is maintained by Nrwl is found in the [Nrwl/nx repo](https://github.com/nrwl/nx/tree/master/packages). \\\n> A list of custom plugins created by the community is found in the [Community](/community) section.\n> Plugins are written using Nx Devkit. **Read [Nx Devkit](/devkit/index) for more information.**\n\n\n\n## Generating a Plugin\n\nTo get started with building a Nx Plugin, run the following command:\n\n```bash\nnpx create-nx-plugin my-org --pluginName my-plugin\n```\n\nThis command creates a brand new workspace, and sets up a pre-configured plugin with the specified name.\n\n> Note, the command above will create a plugin the package name set to `@my-org/my-plugin`. You can pass `--importPath` to provide a different package name.\n\n> If you do not want to create a new workspace, install the `@nrwl/nx-plugin` dependency in an already existing workspace with npm or yarn. Then run `nx g @nrwl/nx-plugin:plugin [pluginName]`.\n\nA new plugin is created with a default generator, executor, and e2e app.\n\n## Generator\n\nThe created generator contains boilerplate that will do the following:\n\n- Normalize a schema (the options that the generator accepts)\n- Update the `workspace.json`\n- Add the plugin's project to the `nx.json` file\n- Add files to the disk using templates\n\nThere will be a exported default function that will be the main entry for the generator.\n\n### Generator options\n\nThe `schema.d.ts` file contains all the options that the generator supports. By default, it includes `directory`, `tags`, and `name` as the options. If more options need to be added, please update this file and the `schema.json` file.\n\n> Note: The `schema.d.ts` file is used for type checking inside the implementation file. It should match the properties in `schema.json`.\n\n### Adding more generators\n\nTo add more generators to the plugin, run the following command:\n`nx generate @nrwl/nx-plugin:generator [generatorName] --project=[pluginName]`.\n\nThis will scaffold out a new generator and update the necessary files to support it.\n\n### Generator Testing\n\nThe generator spec file includes boilerplate to help get started with testing. This includes setting up an empty workspace.\n\nThese tests should ensure that files within the tree (created with `createTreeWithEmptyWorkspace`) are in the correct place, and contain the right content.\n\nFull E2Es are supported (and recommended) and will run everything on the file system like a user would.\n\n## Executor\n\nThe default executor is set up to just emit a console log. Some examples of what an executor can do are:\n\n- Support different languages, (Java, Go, Python, C#)\n- Compile new UI framework components\n- Deploy an app on a CDN\n- Publish to NPM\n- and many more!\n\n### Adding more executors\n\nTo add more executors to the plugin, run the following command:\n`nx generate @nrwl/nx-plugin:executor [executor] --project=[pluginName]`.\n\nThis will scaffold out a new generator and update the necessary files to support it.\n\n### Executor testing\n\nThe executor spec file contains boilerplate to run the default exported function from the executor.\n\nThese tests should make sure that the executor is executing and calling the functions that it relies on.\n\nFull E2Es are supported (and recommended) and will run everything on the file system like a user would.\n\n## Testing your plugin\n\nOne of the biggest benefits that the Nx Plugin package provides is support for E2E and unit testing.\n\nWhen the E2E app runs, a temporary E2E directory is created in the root of the workspace. This directory is a blank Nx workspace, and will have the plugin's built package installed locally.\n\n### E2E Testing file\n\nWhen the plugin is generated, a test file is created in the `my-plugin-e2e` app. Inside this test file, there are already tests for making sure that the executor ran, checking if directories are created with the `--directory` option, and checking if tags are added to the project configuration.\n\nWe'll go over a few parts of a test file below:\n\n```typescript\nit('should create my-plugin', async (done) => {\n const plugin = uniq('my-plugin');\n ensureNxProject('@my-org/my-plugin', 'dist/packages/my-plugin');\n await runNxCommandAsync(`generate @my-org/my-plugin:myPlugin ${plugin}`);\n\n const result = await runNxCommandAsync(`build ${plugin}`);\n expect(result.stdout).toContain('Executor ran');\n\n done();\n});\n```\n\n- The `uniq` function creates a random name with the prefix and a random number.\n- The `ensureNxProject` is the function that will create the temporary directory. It takes two arguments, the plugin package name and the dist directory of when it's built.\n- The `runNxCommandAsync` will execute a `nx` command in the E2E directory.\n\nThere are additional functions that the `@nrwl/nx-plugin/testing` package exports. Most of them are file utilities to manipulate and read files in the E2E directory.\n\n## Including Assets\n\nSometimes you might want to include some assets with the plugin. This might be a image or some additional binaries.\n\nTo make sure that assets are copied to the dist folder, open the plugin's `project.json` file. Inside the `build` property, add additional assets. By default, all `.md` files in the root, all non-ts files in folders, and the `generators.json` and `executors.json` files are included.\n\n```json\n\"build\": {\n \"executor\": \"@nrwl/node:package\",\n \"options\": {\n // shortened...\n \"assets\": [\n \"packages/my-plugin/*.md\",\n {\n \"input\": \"./packages/my-plugin/src\",\n \"glob\": \"**/*.!(ts)\",\n \"output\": \"./src\"\n },\n {\n \"input\": \"./packages/my-plugin\",\n \"glob\": \"generators.json\",\n \"output\": \".\"\n },\n {\n \"input\": \"./packages/my-plugin\",\n \"glob\": \"executors.json\",\n \"output\": \".\"\n }\n ]\n }\n}\n```\n\n## Using your Nx Plugin\n\nTo use your plugin, simply list it in `nx.json` or use its generators and executors as you would for any other plugin. This could look like `nx g @my-org/my-plugin:lib` for generators or `\"executor\": \"@my-org/my-plugin:build\"` for executors. It should be usable in all of the same ways as published plugins in your local workspace immediately after generating it. This includes setting it up as the default collection in `nx.json`, which would allow you to run `nx g lib` and hit your plugin's generator.\n\n## Publishing your Nx Plugin\n\nIn order to use your plugin in other workspaces or share it with the community, you will need to publish it to an npm registry. To publish your plugin follow these steps:\n\n1. Build your plugin with the command `nx run my-plugin:build`\n1. `npm publish ./dist/package/my-plugin` and follow the prompts from npm.\n1. That's it!\n\n> Note: currently you will have to modify the `package.json` version by yourself or with a tool.\n\nAfter that, you can then install your plugin like any other npm package,\n`npm i -D @my-org/my-plugin` or `yarn add -D @my-org/my-plugin`.\n\n### Listing your Nx Plugin\n\nNx provides a utility (`nx list`) that lists both core and community plugins. To submit your plugin, please follow the steps below:\n\n- Fork the [Nx repo](https://github.com/nrwl/nx/fork) (if you haven't already)\n- Update the [`community/approved-plugins.json` file](https://github.com/nrwl/nx/blob/master/community/approved-plugins.json) with a new entry for your plugin that includes name, url and description\n- Use the following commit message template: `chore(core): nx plugin submission [PLUGIN_NAME]`\n- push your changes, and run `yarn submit-plugin`\n\n> The `yarn submit-plugin` command automatically opens the Github pull request process with the correct template.\n\nWe will then verify the plugin, offer suggestions or merge the pull request!\n\n## Preset\n\nA Preset is a customization option which you provide when creating a new workspace. TS, Node, React are some of the internal presets that Nx provides by default.\n\n\n \n### Custom Preset\n\nAt its core a preset is a generator, which we can create inside of a plugin.\nIf you **don't** have an existing plugin you can create one by running\n\n```bash\n npx create-nx-plugin my-org --pluginName my-plugin\n```\n\nTo create our preset inside of our plugin we can run\n\n```bash\n nx generate @nrwl/nx-plugin:generator --name=preset --project=happynrwl\n```\n\n> Note: the word `preset` is required for the name of this generator\n\nYou should have a similar structure to this:\n\n```treeview\nhappynrwl/\n\t├── e2e\n\t├── jest.config.js\n\t├── jest.preset.js\n\t├── nx.json\n\t├── package-lock.json\n\t├── package.json\n\t├── packages\n\t│ └── happynrwl\n\t│ ├── src\n\t│ │ ├── executors\n\t│ │ ├── generators\n\t│ │ │ ├── happynrwl\n\t│ │ │ └── preset \t\t// <------------- Here\n\t│ │ └── index.ts\n\t├── tools\n\t├── tsconfig.base.json\n\t└── workspace.json\n```\n\nAfter the command is finished, the preset generator is created under the folder named **preset**.\nThe **generator.ts** provides an entry point to the generator. This file contains a function that is called to perform manipulations on a tree that represents the file system. The **schema.json** provides a description of the generator, available options, validation information, and default values.\n\nHere is the sample generator function which you can customize to meet your needs.\n\n```typescript\nexport default async function (tree: Tree, options: PresetGeneratorSchema) {\n const normalizedOptions = normalizeOptions(tree, options);\n addProjectConfiguration(tree, normalizedOptions.projectName, {\n root: normalizedOptions.projectRoot,\n projectType: 'application',\n sourceRoot: `${normalizedOptions.projectRoot}/src`,\n targets: {\n exec: {\n executor: 'nx:run-commands',\n options: {\n command: `node ${projectRoot}/src/index.js`,\n },\n },\n },\n tags: normalizedOptions.parsedTags,\n });\n addFiles(tree, normalizedOptions);\n await formatFiles(tree);\n}\n```\n\nTo get an in-depth guide on customizing/running or debugging your generator see [workspace generators](https://nx.dev/generators/workspace-generators#running-a-workspace-generator).\n\n#### Usage\n\nBefore you are able to use your newly created preset you must package and publish it to a registry.\n\nAfter you have published your plugin to a registry you can now use your preset when creating a new workspace\n\n```bash\nnpx create-nx-workspace my-workspace --preset=my-plugin-name\n```\n" + "content": "Nx plugins are npm packages that contain generators and executors to extend a Nx workspace. Generators are blueprints to create new files from templates, and executors run those files. These plugins also update the `nx.json` when generating new libs or apps.\n\n> A list of plugins that is maintained by Nrwl is found in the [Nrwl/nx repo](https://github.com/nrwl/nx/tree/master/packages). \\\n> A list of custom plugins created by the community is found in the [Community](/community) section.\n> Plugins are written using Nx Devkit. **Read [Nx Devkit](/devkit/index) for more information.**\n\n{% youtube\nsrc=\"https://www.youtube.com/embed/fC1-4fAZDP4\"\ntitle=\"Nx Tutorial: Building Custom Plugins for Nx\"\nwidth=\"100%\" /%}\n\n## Generating a Plugin\n\nTo get started with building a Nx Plugin, run the following command:\n\n```bash\nnpx create-nx-plugin my-org --pluginName my-plugin\n```\n\nThis command creates a brand-new workspace, and sets up a pre-configured plugin with the specified name.\n\n> Note, the command above will create a plugin the package name set to `@my-org/my-plugin`. You can pass `--importPath` to provide a different package name.\n\n> If you do not want to create a new workspace, install the `@nrwl/nx-plugin` dependency in an already existing workspace with npm or yarn. Then run `nx g @nrwl/nx-plugin:plugin [pluginName]`.\n\nA new plugin is created with a default generator, executor, and e2e app.\n\n## Generator\n\nThe created generator contains boilerplate that will do the following:\n\n- Normalize a schema (the options that the generator accepts)\n- Update the `workspace.json`\n- Add the plugin's project to the `nx.json` file\n- Add files to the disk using templates\n\nThere will be an exported default function that will be the main entry for the generator.\n\n### Generator options\n\nThe `schema.d.ts` file contains all the options that the generator supports. By default, it includes `directory`, `tags`, and `name` as the options. If more options need to be added, please update this file and the `schema.json` file.\n\n> Note: The `schema.d.ts` file is used for type checking inside the implementation file. It should match the properties in `schema.json`.\n\n### Adding more generators\n\nTo add more generators to the plugin, run the following command:\n`nx generate @nrwl/nx-plugin:generator [generatorName] --project=[pluginName]`.\n\nThis will scaffold out a new generator and update the necessary files to support it.\n\n### Generator Testing\n\nThe generator spec file includes boilerplate to help get started with testing. This includes setting up an empty workspace.\n\nThese tests should ensure that files within the tree (created with `createTreeWithEmptyWorkspace`) are in the correct place, and contain the right content.\n\nFull E2Es are supported (and recommended) and will run everything on the file system like a user would.\n\n## Executor\n\nThe default executor is set up to just emit a console log. Some examples of what an executor can do are:\n\n- Support different languages, (Java, Go, Python, C#)\n- Compile new UI framework components\n- Deploy an app on a CDN\n- Publish to NPM\n- and many more!\n\n### Adding more executors\n\nTo add more executors to the plugin, run the following command:\n`nx generate @nrwl/nx-plugin:executor [executor] --project=[pluginName]`.\n\nThis will scaffold out a new generator and update the necessary files to support it.\n\n### Executor testing\n\nThe executor spec file contains boilerplate to run the default exported function from the executor.\n\nThese tests should make sure that the executor is executing and calling the functions that it relies on.\n\nFull E2Es are supported (and recommended) and will run everything on the file system like a user would.\n\n## Testing your plugin\n\nOne of the biggest benefits that the Nx Plugin package provides is support for E2E and unit testing.\n\nWhen the E2E app runs, a temporary E2E directory is created in the root of the workspace. This directory is a blank Nx workspace, and will have the plugin's built package installed locally.\n\n### E2E Testing file\n\nWhen the plugin is generated, a test file is created in the `my-plugin-e2e` app. Inside this test file, there are already tests for making sure that the executor ran, checking if directories are created with the `--directory` option, and checking if tags are added to the project configuration.\n\nWe'll go over a few parts of a test file below:\n\n```typescript\nit('should create my-plugin', async (done) => {\n const plugin = uniq('my-plugin');\n ensureNxProject('@my-org/my-plugin', 'dist/packages/my-plugin');\n await runNxCommandAsync(`generate @my-org/my-plugin:myPlugin ${plugin}`);\n\n const result = await runNxCommandAsync(`build ${plugin}`);\n expect(result.stdout).toContain('Executor ran');\n\n done();\n});\n```\n\n- The `uniq` function creates a random name with the prefix and a random number.\n- The `ensureNxProject` is the function that will create the temporary directory. It takes two arguments, the plugin package name and the dist directory of when it's built.\n- The `runNxCommandAsync` will execute a `nx` command in the E2E directory.\n\nThere are additional functions that the `@nrwl/nx-plugin/testing` package exports. Most of them are file utilities to manipulate and read files in the E2E directory.\n\n## Including Assets\n\nSometimes you might want to include some assets with the plugin. This might be a image or some additional binaries.\n\nTo make sure that assets are copied to the dist folder, open the plugin's `project.json` file. Inside the `build` property, add additional assets. By default, all `.md` files in the root, all non-ts files in folders, and the `generators.json` and `executors.json` files are included.\n\n```json\n\"build\": {\n \"executor\": \"@nrwl/node:package\",\n \"options\": {\n // shortened...\n \"assets\": [\n \"packages/my-plugin/*.md\",\n {\n \"input\": \"./packages/my-plugin/src\",\n \"glob\": \"**/*.!(ts)\",\n \"output\": \"./src\"\n },\n {\n \"input\": \"./packages/my-plugin\",\n \"glob\": \"generators.json\",\n \"output\": \".\"\n },\n {\n \"input\": \"./packages/my-plugin\",\n \"glob\": \"executors.json\",\n \"output\": \".\"\n }\n ]\n }\n}\n```\n\n## Using your Nx Plugin\n\nTo use your plugin, simply list it in `nx.json` or use its generators and executors as you would for any other plugin. This could look like `nx g @my-org/my-plugin:lib` for generators or `\"executor\": \"@my-org/my-plugin:build\"` for executors. It should be usable in all of the same ways as published plugins in your local workspace immediately after generating it. This includes setting it up as the default collection in `nx.json`, which would allow you to run `nx g lib` and hit your plugin's generator.\n\n## Publishing your Nx Plugin\n\nIn order to use your plugin in other workspaces or share it with the community, you will need to publish it to an npm registry. To publish your plugin follow these steps:\n\n1. Build your plugin with the command `nx run my-plugin:build`\n1. `npm publish ./dist/package/my-plugin` and follow the prompts from npm.\n1. That's it!\n\n> Note: currently you will have to modify the `package.json` version by yourself or with a tool.\n\nAfter that, you can then install your plugin like any other npm package,\n`npm i -D @my-org/my-plugin` or `yarn add -D @my-org/my-plugin`.\n\n### Listing your Nx Plugin\n\nNx provides a utility (`nx list`) that lists both core and community plugins. To submit your plugin, please follow the steps below:\n\n- Fork the [Nx repo](https://github.com/nrwl/nx/fork) (if you haven't already)\n- Update the [`community/approved-plugins.json` file](https://github.com/nrwl/nx/blob/master/community/approved-plugins.json) with a new entry for your plugin that includes name, url and description\n- Use the following commit message template: `chore(core): nx plugin submission [PLUGIN_NAME]`\n- push your changes, and run `yarn submit-plugin`\n\n> The `yarn submit-plugin` command automatically opens the Github pull request process with the correct template.\n\nWe will then verify the plugin, offer suggestions or merge the pull request!\n\n## Preset\n\nA Preset is a customization option which you provide when creating a new workspace. TS, Node, React are some internal presets that Nx provides by default.\n\n{% youtube\nsrc=\"https://www.youtube.com/embed/yGUrF0-uqaU\"\ntitle=\"Develop a Nx Preset for your Nx Plugin\"\nwidth=\"100%\" /%}\n\n### Custom Preset\n\nAt its core a preset is a generator, which we can create inside of a plugin.\nIf you **don't** have an existing plugin you can create one by running\n\n```bash\n npx create-nx-plugin my-org --pluginName my-plugin\n```\n\nTo create our preset inside of our plugin we can run\n\n```bash\n nx generate @nrwl/nx-plugin:generator --name=preset --project=happynrwl\n```\n\n> Note: the word `preset` is required for the name of this generator\n\nYou should have a similar structure to this:\n\n```treeview\nhappynrwl/\n\t├── e2e\n\t├── jest.config.js\n\t├── jest.preset.js\n\t├── nx.json\n\t├── package-lock.json\n\t├── package.json\n\t├── packages\n\t│ └── happynrwl\n\t│ ├── src\n\t│ │ ├── executors\n\t│ │ ├── generators\n\t│ │ │ ├── happynrwl\n\t│ │ │ └── preset \t\t// <------------- Here\n\t│ │ └── index.ts\n\t├── tools\n\t├── tsconfig.base.json\n\t└── workspace.json\n```\n\nAfter the command is finished, the preset generator is created under the folder named **preset**.\nThe **generator.ts** provides an entry point to the generator. This file contains a function that is called to perform manipulations on a tree that represents the file system. The **schema.json** provides a description of the generator, available options, validation information, and default values.\n\nHere is the sample generator function which you can customize to meet your needs.\n\n```typescript\nexport default async function (tree: Tree, options: PresetGeneratorSchema) {\n const normalizedOptions = normalizeOptions(tree, options);\n addProjectConfiguration(tree, normalizedOptions.projectName, {\n root: normalizedOptions.projectRoot,\n projectType: 'application',\n sourceRoot: `${normalizedOptions.projectRoot}/src`,\n targets: {\n exec: {\n executor: 'nx:run-commands',\n options: {\n command: `node ${projectRoot}/src/index.js`,\n },\n },\n },\n tags: normalizedOptions.parsedTags,\n });\n addFiles(tree, normalizedOptions);\n await formatFiles(tree);\n}\n```\n\nTo get an in-depth guide on customizing/running or debugging your generator see [workspace generators](https://nx.dev/generators/workspace-generators#running-a-workspace-generator).\n\n#### Usage\n\nBefore you are able to use your newly created preset you must package and publish it to a registry.\n\nAfter you have published your plugin to a registry you can now use your preset when creating a new workspace\n\n```bash\nnpx create-nx-workspace my-workspace --preset=my-plugin-name\n```\n" } ], "generators": [ diff --git a/docs/generated/packages/storybook.json b/docs/generated/packages/storybook.json index 40a8070e60..b5fdad5673 100644 --- a/docs/generated/packages/storybook.json +++ b/docs/generated/packages/storybook.json @@ -34,7 +34,7 @@ "id": "migrate-webpack-final-react", "name": "Migrate to the Nrwl React Storybook Preset", "file": "shared/guides/storybook/migrate-webpack-final-react", - "content": "# Nrwl React Storybook Preset\n\nNx 12.7 comes with a dedicated Storybook preset for React which drammatically simplifies the Storybook setup and makes sure that Storybook uses the same webpack configuration as your React applications running within an Nx workspace.\n\n\n\nHere are the main differences to the previous versions of Nx:\n\n- there's no `webpack.config.js`; Custom webpack configurations can be added in the `webpackFinal` property of the `main.js` file\n- the `main.js` file now contains a predefined Storybook preset exported by `@nrwl/react/plugins/storybook`.\n\nHere's an example of a newly generated `main.js` file:\n\n```javascript\n// project-level .storybook/main.js file\nconst rootMain = require('../../../.storybook/main');\n\nmodule.exports = {\n ...rootMain,\n\n core: {\n ...rootMain.core,\n // opt-into Storybook Webpack 5\n builder: 'webpack5'\n }\n\n stories: [\n ...rootMain.stories,\n '../src/lib/**/*.stories.mdx',\n '../src/lib/**/*.stories.@(js|jsx|ts|tsx)',\n ],\n addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'],\n webpackFinal: async (config, { configType }) => {\n // apply any global webpack configs that might have been specified in .storybook/main.js\n if (rootMain.webpackFinal) {\n config = await rootMain.webpackFinal(config, { configType });\n }\n\n // add your own webpack tweaks if needed\n\n return config;\n },\n};\n```\n\nAt the Nx workspace root level, the configuration file looks as follows:\n\n```javascript\n// root level .storybook/main.js file\nmodule.exports = {\n stories: [],\n addons: ['@storybook/addon-essentials'],\n // uncomment the property below if you want to apply some webpack config globally\n // webpackFinal: async (config, { configType }) => {\n // // Make whatever fine-grained changes you need that should apply to all storybook configs\n\n // // Return the altered config\n // return config;\n // },\n};\n```\n\n## Migrating\n\nIf you're upgrading from a lower version of Nx, your old Storybook configuration will still work. New configurations generated will use the new syntax as shown above. The newly generated code will also make sure to extend from a global `webpack.config.js` which might exist in the root-level `.storybook/` directory of your Nx workspace.\n\nThis gives you the flexibility to incrementally migrate your configurations.\n\nHere's the step-by-step migration process:\n\n### 1. adjust the `main.js` file\n\nRestructure your `main.js` file so that it looks like in the example illustrated above.\n\nIf you need to keep your root-level `.storybook/webpack.config.js` for now, then make sure you adjust the `main.js` in a way that it properly calls the root-level `webpack.config.js` to inherit all of the global configurations.\n\n```javascript\nconst rootMain = require('../../../.storybook/main');\nconst rootWebpackConfig = require('../../../.storybook/webpack.config');\n\nmodule.exports = {\n ...rootMain,\n ...\n webpackFinal: async (config) => {\n // for backwards compatibility call the `rootWebpackConfig`\n // this can be removed once that one is migrated fully to\n // use the `webpackFinal` property in the `main.js` file\n config = rootWebpackConfig({ config });\n\n // add your own webpack tweaks if needed\n\n return config;\n },\n};\n```\n\n**Note:** The easiest way is probably to generate a new library and Storybook configuration and then copy & paste the `main.js`.\n\n### 2. Move any custom webpack configuration to `webpackFinal`\n\nIn previous versions of Nx a custom `webpack.config.js` was generated with the following content:\n\n```javascript\nmodule.exports = async ({ config, mode }) => {\n config = await rootWebpackConfig({ config, mode });\n\n const tsPaths = new TsconfigPathsPlugin({\n configFile: './tsconfig.base.json',\n });\n\n config.resolve.plugins\n ? config.resolve.plugins.push(tsPaths)\n : (config.resolve.plugins = [tsPaths]);\n\n // Found this here: https://github.com/nrwl/nx/issues/2859\n // And copied the part of the solution that made it work\n\n const svgRuleIndex = config.module.rules.findIndex((rule) => {\n const { test } = rule;\n\n return test.toString().startsWith('/\\\\.(svg|ico');\n });\n config.module.rules[svgRuleIndex].test =\n /\\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\\?.*)?$/;\n\n config.module.rules.push(\n {\n test: /\\.(png|jpe?g|gif|webp)$/,\n loader: require.resolve('url-loader'),\n options: {\n limit: 10000, // 10kB\n name: '[name].[hash:7].[ext]',\n },\n },\n {\n test: /\\.svg$/,\n oneOf: [\n // If coming from JS/TS file, then transform into React component using SVGR.\n {\n issuer: {\n test: /\\.[jt]sx?$/,\n },\n use: [\n {\n loader: require.resolve('@svgr/webpack'),\n options: {\n svgo: false,\n titleProp: true,\n ref: true,\n },\n },\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: 10000, // 10kB\n name: '[name].[hash:7].[ext]',\n esModule: false,\n },\n },\n ],\n },\n // Fallback to plain URL loader.\n {\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: 10000, // 10kB\n name: '[name].[hash:7].[ext]',\n },\n },\n ],\n },\n ],\n }\n );\n\n return config;\n};\n```\n\nSuch webpack file is no more needed as the `@nrwl/react/plugins/storybook` now takes care of it.\n\nIn case you made custom modifications to the `webpack.config.js` file, you need to move them over to the `main.js` `webpackFinal` property and then delete the `webpack.config.js`.\n\n### 3. Remove the root-level `.storybook/webpack.config.js` file\n\nOnce you've migrated all your libraries, you can think about removing the root-level `.storybook/webpack.config.js` file and migrate any custom configuration there to `.storybook/main.js` `webpackFinal` property in the very same folder.\n\n### 4. Opting in to Webpack 5\n\nIf you choose to opt-in to Webpack 5, by specifying `builder: 'webpack5'` in your project's `.storybook/main.(js|ts)` (as shown above, in the example of a newly generated `main.js` file), don't forget to add the Storybook dependencies for Webpack 5 to work:\n\n```shell\nyarn add -D @storybook/builder-webpack5 @storybook/manager-webpack5\n```\n\nor if you're using `npm`:\n\n```shell\nnpm install --save-dev @storybook/builder-webpack5 @storybook/manager-webpack5\n```\n" + "content": "# Nrwl React Storybook Preset\n\nNx 12.7 comes with a dedicated Storybook preset for React which drammatically simplifies the Storybook setup and makes sure that Storybook uses the same webpack configuration as your React applications running within an Nx workspace.\n\n{% youtube\nsrc=\"https://www.youtube.com/embed/oUE74McS_NY\"\ntitle=\"New in Nx 12.7: React Storybook Preset\"\nwidth=\"100%\" /%}\n\nHere are the main differences to the previous versions of Nx:\n\n- there's no `webpack.config.js`; Custom webpack configurations can be added in the `webpackFinal` property of the `main.js` file\n- the `main.js` file now contains a predefined Storybook preset exported by `@nrwl/react/plugins/storybook`.\n\nHere's an example of a newly generated `main.js` file:\n\n```javascript\n// project-level .storybook/main.js file\nconst rootMain = require('../../../.storybook/main');\n\nmodule.exports = {\n ...rootMain,\n\n core: {\n ...rootMain.core,\n // opt-into Storybook Webpack 5\n builder: 'webpack5'\n }\n\n stories: [\n ...rootMain.stories,\n '../src/lib/**/*.stories.mdx',\n '../src/lib/**/*.stories.@(js|jsx|ts|tsx)',\n ],\n addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'],\n webpackFinal: async (config, { configType }) => {\n // apply any global webpack configs that might have been specified in .storybook/main.js\n if (rootMain.webpackFinal) {\n config = await rootMain.webpackFinal(config, { configType });\n }\n\n // add your own webpack tweaks if needed\n\n return config;\n },\n};\n```\n\nAt the Nx workspace root level, the configuration file looks as follows:\n\n```javascript\n// root level .storybook/main.js file\nmodule.exports = {\n stories: [],\n addons: ['@storybook/addon-essentials'],\n // uncomment the property below if you want to apply some webpack config globally\n // webpackFinal: async (config, { configType }) => {\n // // Make whatever fine-grained changes you need that should apply to all storybook configs\n\n // // Return the altered config\n // return config;\n // },\n};\n```\n\n## Migrating\n\nIf you're upgrading from a lower version of Nx, your old Storybook configuration will still work. New configurations generated will use the new syntax as shown above. The newly generated code will also make sure to extend from a global `webpack.config.js` which might exist in the root-level `.storybook/` directory of your Nx workspace.\n\nThis gives you the flexibility to incrementally migrate your configurations.\n\nHere's the step-by-step migration process:\n\n### 1. adjust the `main.js` file\n\nRestructure your `main.js` file so that it looks like in the example illustrated above.\n\nIf you need to keep your root-level `.storybook/webpack.config.js` for now, then make sure you adjust the `main.js` in a way that it properly calls the root-level `webpack.config.js` to inherit all of the global configurations.\n\n```javascript\nconst rootMain = require('../../../.storybook/main');\nconst rootWebpackConfig = require('../../../.storybook/webpack.config');\n\nmodule.exports = {\n ...rootMain,\n ...\n webpackFinal: async (config) => {\n // for backwards compatibility call the `rootWebpackConfig`\n // this can be removed once that one is migrated fully to\n // use the `webpackFinal` property in the `main.js` file\n config = rootWebpackConfig({ config });\n\n // add your own webpack tweaks if needed\n\n return config;\n },\n};\n```\n\n**Note:** The easiest way is probably to generate a new library and Storybook configuration and then copy & paste the `main.js`.\n\n### 2. Move any custom webpack configuration to `webpackFinal`\n\nIn previous versions of Nx a custom `webpack.config.js` was generated with the following content:\n\n```javascript\nmodule.exports = async ({ config, mode }) => {\n config = await rootWebpackConfig({ config, mode });\n\n const tsPaths = new TsconfigPathsPlugin({\n configFile: './tsconfig.base.json',\n });\n\n config.resolve.plugins\n ? config.resolve.plugins.push(tsPaths)\n : (config.resolve.plugins = [tsPaths]);\n\n // Found this here: https://github.com/nrwl/nx/issues/2859\n // And copied the part of the solution that made it work\n\n const svgRuleIndex = config.module.rules.findIndex((rule) => {\n const { test } = rule;\n\n return test.toString().startsWith('/\\\\.(svg|ico');\n });\n config.module.rules[svgRuleIndex].test =\n /\\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\\?.*)?$/;\n\n config.module.rules.push(\n {\n test: /\\.(png|jpe?g|gif|webp)$/,\n loader: require.resolve('url-loader'),\n options: {\n limit: 10000, // 10kB\n name: '[name].[hash:7].[ext]',\n },\n },\n {\n test: /\\.svg$/,\n oneOf: [\n // If coming from JS/TS file, then transform into React component using SVGR.\n {\n issuer: {\n test: /\\.[jt]sx?$/,\n },\n use: [\n {\n loader: require.resolve('@svgr/webpack'),\n options: {\n svgo: false,\n titleProp: true,\n ref: true,\n },\n },\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: 10000, // 10kB\n name: '[name].[hash:7].[ext]',\n esModule: false,\n },\n },\n ],\n },\n // Fallback to plain URL loader.\n {\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: 10000, // 10kB\n name: '[name].[hash:7].[ext]',\n },\n },\n ],\n },\n ],\n }\n );\n\n return config;\n};\n```\n\nSuch webpack file is no more needed as the `@nrwl/react/plugins/storybook` now takes care of it.\n\nIn case you made custom modifications to the `webpack.config.js` file, you need to move them over to the `main.js` `webpackFinal` property and then delete the `webpack.config.js`.\n\n### 3. Remove the root-level `.storybook/webpack.config.js` file\n\nOnce you've migrated all your libraries, you can think about removing the root-level `.storybook/webpack.config.js` file and migrate any custom configuration there to `.storybook/main.js` `webpackFinal` property in the very same folder.\n\n### 4. Opting in to Webpack 5\n\nIf you choose to opt-in to Webpack 5, by specifying `builder: 'webpack5'` in your project's `.storybook/main.(js|ts)` (as shown above, in the example of a newly generated `main.js` file), don't forget to add the Storybook dependencies for Webpack 5 to work:\n\n```shell\nyarn add -D @storybook/builder-webpack5 @storybook/manager-webpack5\n```\n\nor if you're using `npm`:\n\n```shell\nnpm install --save-dev @storybook/builder-webpack5 @storybook/manager-webpack5\n```\n" }, { "id": "migrate-webpack-final-angular", diff --git a/docs/nx-cloud/intro/nx-cloud.md b/docs/nx-cloud/intro/nx-cloud.md index 463785c882..63c9578b77 100644 --- a/docs/nx-cloud/intro/nx-cloud.md +++ b/docs/nx-cloud/intro/nx-cloud.md @@ -14,8 +14,14 @@ Most developers will benefit from Nx Cloud without ever changing any of their wo The [top level organization page](https://nx.app/orgs/5e38af6de037b5000598b2d6/workspaces/5edaf12087863a0005781f17) displays recent runs and a helpful dashboard of information about commands run in the repository. - +{% iframe +src="https://nx.app/orgs/5e38af6de037b5000598b2d6/workspaces/5edaf12087863a0005781f17?hideHeader=true" +title="Nx Cloud dashboard" +width="100%" /%} Each branch in the repository has its own [dedicated page](https://nx.app/branch?workspaceId=5edaf12087863a0005781f17&branchName=master) where you can view agent utilization and a waterfall task execution graph for the most recent runs against that branch. - +{% iframe +src="https://nx.app/branch?workspaceId=5edaf12087863a0005781f17&branchName=master&hideHeader=true" +title="Nx Cloud branch view" +width="100%" /%} diff --git a/docs/shared/angular-tutorial/01-create-application.md b/docs/shared/angular-tutorial/01-create-application.md index 891c9f1b50..593c56c2d3 100644 --- a/docs/shared/angular-tutorial/01-create-application.md +++ b/docs/shared/angular-tutorial/01-create-application.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 1: Create Application - +{% youtube +src="https://www.youtube.com/embed/i37yJKK8qGI" +title="Nx.dev Tutorial | Angular | Step 1: Create Application" +width="100%" /%} In this tutorial you use Nx to build a full-stack application out of common libraries using modern technologies like Cypress and Nest. diff --git a/docs/shared/angular-tutorial/02-add-e2e-test.md b/docs/shared/angular-tutorial/02-add-e2e-test.md index 58bef5d334..428d6d847d 100644 --- a/docs/shared/angular-tutorial/02-add-e2e-test.md +++ b/docs/shared/angular-tutorial/02-add-e2e-test.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 2: Add E2E Tests - +{% youtube +src="https://www.youtube.com/embed/owRAO75DIR4" +title="Nx.dev Tutorial | Angular | Step 2: Add E2E Test" +width="100%" /%} By default, Nx uses [Cypress](/cypress/overview) to run E2E tests. diff --git a/docs/shared/angular-tutorial/03-display-todos.md b/docs/shared/angular-tutorial/03-display-todos.md index c3e46d00de..124c57eac3 100644 --- a/docs/shared/angular-tutorial/03-display-todos.md +++ b/docs/shared/angular-tutorial/03-display-todos.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 3: Display Todos - +{% youtube +src="https://www.youtube.com/embed/JlKAwGXmpac" +title="Nx.dev Tutorial | Angular | Step 3: Display Todos" +width="100%" /%} Great! You have a failing E2E test. Now you can make it pass! diff --git a/docs/shared/angular-tutorial/04-connect-to-api.md b/docs/shared/angular-tutorial/04-connect-to-api.md index bb79a5386f..087412ef74 100644 --- a/docs/shared/angular-tutorial/04-connect-to-api.md +++ b/docs/shared/angular-tutorial/04-connect-to-api.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 4: Connect to an API - +{% youtube +src="https://www.youtube.com/embed/JlKAwGXmpac" +title="Nx.dev Tutorial | Angular | Step 4: Connect to API" +width="100%" /%} Real-world applications do not live in isolation — they need APIs to talk to. Setup your app to talk to an API. diff --git a/docs/shared/angular-tutorial/05-add-node-app.md b/docs/shared/angular-tutorial/05-add-node-app.md index bd7cbe34be..041a18afa5 100644 --- a/docs/shared/angular-tutorial/05-add-node-app.md +++ b/docs/shared/angular-tutorial/05-add-node-app.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 5: Add Node Application Implementing an API - +{% youtube +src="https://www.youtube.com/embed/SsCx2WErVTI" +title="Nx.dev Tutorial | Angular | Step 5: Add Node Application Implementing API" +width="100%" /%} The requests fail because the API has not been created yet. Using Nx you can develop node applications next to your Angular applications. You can use same commands to run and test them. You can share code between the backend and the frontend. Use this capability to implement the API service. diff --git a/docs/shared/angular-tutorial/06-proxy.md b/docs/shared/angular-tutorial/06-proxy.md index 70c934a049..d858b7196e 100644 --- a/docs/shared/angular-tutorial/06-proxy.md +++ b/docs/shared/angular-tutorial/06-proxy.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 6: Proxy - +{% youtube +src="https://www.youtube.com/embed/7d6jDAbmVnE" +title="Nx.dev Tutorial | Angular | Step 6: Configure Proxy" +width="100%" /%} You passed `--frontendProject=todos` when creating the node application. What did that argument do? diff --git a/docs/shared/angular-tutorial/07-share-code.md b/docs/shared/angular-tutorial/07-share-code.md index 61e1959edb..bd0643f3fb 100644 --- a/docs/shared/angular-tutorial/07-share-code.md +++ b/docs/shared/angular-tutorial/07-share-code.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 7: Share Code - +{% youtube +src="https://www.youtube.com/embed/icyOSQ6gAm0" +title="Nx.dev Tutorial | Angular | Step 7: Share Code" +width="100%" /%} Awesome! The application is working end to end! However, there is a problem. Both the backend and the frontend define the `Todo` interface. The interface is in sync now, but in a real application, over time, it will diverge, and, as a result, runtime errors will creep in. You should share this interface between the backend and the frontend. In Nx, you can do this by creating a library. diff --git a/docs/shared/angular-tutorial/08-create-libs.md b/docs/shared/angular-tutorial/08-create-libs.md index dd49256082..009698b91a 100644 --- a/docs/shared/angular-tutorial/08-create-libs.md +++ b/docs/shared/angular-tutorial/08-create-libs.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 8: Create Libs - +{% youtube +src="https://www.youtube.com/embed/szaH7fNw0zg" +title="Nx.dev Tutorial | Angular | Step 8: Create Libraries" +width="100%" /%} Libraries are not just a way to share code in Nx. They are also useful for factoring out code into small units with a well-defined public API. @@ -12,7 +15,7 @@ Every library has an `index.ts` file, which defines its public API. Other applic To illustrate how useful libraries can be, create a library of Angular components. -Use the generate to scaffold a new library: +Use the generator to scaffold a new library: ```sh npx nx g @nrwl/angular:lib ui diff --git a/docs/shared/angular-tutorial/09-dep-graph.md b/docs/shared/angular-tutorial/09-dep-graph.md index f263a020b7..13a6b48503 100644 --- a/docs/shared/angular-tutorial/09-dep-graph.md +++ b/docs/shared/angular-tutorial/09-dep-graph.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 9: Using the Project Graph - +{% youtube +src="https://www.youtube.com/embed/8fr2RukmfW0" +title="Nx.dev Tutorial | Angular | Step 9: Dep Graph" +width="100%" /%} An Nx workspace can contain dozens or hundreds of applications and libraries. As a codebase grows, it becomes more difficult to understand how they depend on each other and the implications of making a particular change. diff --git a/docs/shared/angular-tutorial/10-computation-caching.md b/docs/shared/angular-tutorial/10-computation-caching.md index 0a60b6601c..4aea850da5 100644 --- a/docs/shared/angular-tutorial/10-computation-caching.md +++ b/docs/shared/angular-tutorial/10-computation-caching.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 10: Computation Caching - +{% youtube +src="https://www.youtube.com/embed/HX3--ilBhBs" +title="Nx.dev Tutorial | Angular | Step 10: Use Computation Caching" +width="100%" /%} Nx has built-in computation caching, which helps drastically improve the performance of the commands. diff --git a/docs/shared/angular-tutorial/11-test-affected-projects.md b/docs/shared/angular-tutorial/11-test-affected-projects.md index 550b95fa45..45f1f2153a 100644 --- a/docs/shared/angular-tutorial/11-test-affected-projects.md +++ b/docs/shared/angular-tutorial/11-test-affected-projects.md @@ -1,6 +1,9 @@ # Angular Nx Tutorial - Step 11: Testing Affected Projects - +{% youtube +src="https://www.youtube.com/embed/5t77CPl-bbM" +title="Nx.dev Tutorial | Angular | Step 11: Test Affected Projects" +width="100%" /%} Because Nx understands the project graph of your workspace, Nx is efficient at retesting and rebuilding your projects. diff --git a/docs/shared/ci-overview.md b/docs/shared/ci-overview.md index f549850f1f..13aaca0109 100644 --- a/docs/shared/ci-overview.md +++ b/docs/shared/ci-overview.md @@ -16,7 +16,7 @@ Adding Nx to your CI pipeline makes this more efficient. Nx provides out-of-the-box implementation of CI workflows for `GitHub`, `Azure` and `CircleCI` during the [creation of the Nx workspace](/cli/create-nx-workspace#ci) or later using the [ci-workflow](/packages/workspace/generators/ci-workflow) generator. -
- {children}
-
- );
- },
- pre({ children }) {
- return <>{children}>;
- },
-});
-
-export function Content(props: ContentProps): ReactComponentElement