Skip to main content

Developer preferences

There are some customizations in the monorepo you can set based on what you prefer to use as a developer:

Nx Default Project

NX has a configuration that lets you define a default project/application. This lets you start/server an application by simply run yarn nx start or yarn nx lint without specifying the project. But in order to customize what application you prefer to use, you may create a .env.local file in the root of the moro repository with the environment variable:

NX_DEFAULT_PROJECT=<your-name-space>/<application-name>

Pre-commit hook

Run setup script for the pre-commit hook with:

./devconfig.mjs

This will set up some default processes for quality assurance when you run git commit.

lint-staged options

To change the behavior of lint-staged, you can also manually set the options inside of a file called .env.local:

  • LINT_STAGED_ESLINT=1 To enable a ESLint code linting.
  • LINT_STAGED_JEST=1 To enable a Jest code testing.
  • LINT_STAGED_PRETTIER=1 To enable a prettier code check.
  • OMIT_LINT_STAGED=1 To disable lint-staged completely.
  • OMIT_LINT_STAGED_PATHS=glob To run lint-staged on certain file paths only. More info down below.

Opt-out from running lint-staged

Export an environment variable OMIT_LINT_STAGED=1 or specify paths by OMIT_LINT_STAGED_PATHS=glob containing a glob pattern you want to exclude from the files to be checked. You can add several globes by having a comma as the separator.

Add to .env.local to opt-out from lint-staged:

OMIT_LINT_STAGED_PATHS=<part-of-path>/*,**/*.extention

VSCode formatting

We recommend to set up formatting in VSCode (or your favorite code editor) by enabling "Editor: Format on Save" in the VSCode settings (open with CMD + ;)

Below is an example of what the settings.json could include:

  "prettier.requireConfig": true,
"eslint.alwaysShowStatus": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"prettier.configPath": ".prettierrc.js",
"html.format.contentUnformatted": "",
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

Note: You will have to install the addon "Prettier - Code formatter".

Nx yarn alias

Run nx commands without yarn:

  • add an alias to your command line setup to point to the binary. For bash it would be: alias nx='yarn nx'.
  • use a globally installed binary yarn add g nx.

Common questions

yarn: command not found

The pre-commit hook has probably used a different Node.js binary than your CLI or git client (Sourcetree). You can give the following command a try:

echo "export PATH=\"$(dirname $(which node)):\$PATH\"" > ~/.huskyrc

It will add a .huskyrc file in your system root, letting Husky, during a pre-commit hook know, where your CLIs Node.js binary is located.