NX

GitHub - nrwl/nx-examples: Example repo for Nx workspace

Create a New Workspace

  • Start by creating a new workspace. We can use the following command that will help us set it up.

npx create-nx-workspace@latest myorg --preset=ts

This command

  • myorg is name of workspace (can you rename for you application)

Create a Package

With nx can you help with scaffolding applications

npx nx generate @nrwl/js:library is-even --publishable --importPath @myorg/is-even

This command 2

  • Uses the @nrwl/js plugin's library generator to scaffold a new library named is-even.
  • The --publishable flag makes sure we also get a package.json generated and a publish target we can invoke to publish to NPM.
  • The --importPath allows us to define the name of the NPM package.

The file structure should look like this

├── dist
├── packages/
├── tools/
├── nx.json
├── package.json
├── README.md
└── tsconfig.base.json

Update is-even.ts with this content

export function isEven(x: number): boolean {
  return x % 2 === 0;
}

Push your package to NPM

  • npm run build is-even

  • cd /Users/phutran/Documents/package/myorg/dist/packages/is-even

  • update version package => "version": "0.0.3",

  • npm publish

  • npm publish dist/packages/is-odd

  • npm publish dist/packages/is-check-size

Testing

  • npx nx test [is-even] runs the pre-configured Jest tests for the package
  • npx nx test open-ai-helpers

Build

  • npx nx build open-ai-helpers
  • npx nx build [is-odd]
  • npx nx run-many --target=build
  • npx nx affected --target=build RUN NO CACHE

Lint

  • nx run [is-even]:lint

Learn More