This project was generated using Angular CLI version 22.0.0.
To start a local development server, run:
npm run developOnce the server is running, open your browser and navigate to http://localhost:3026/. The application will automatically reload whenever you modify any of the source files.
- Clone only the remote primary HEAD (default: origin/main)
git clone <url> --single-branch- Only specific branch
git clone <url> --branch <branch> --single-branch [<folder>]git clone <url> --branch <branch>- Cloning repositories using degit
- main branch is default.
npx degit github:user/repo#branch-name <folder-name>- Cloning repositories using gitpick
npx gitpick github_proj_url -b branch-name- Cloning this project with skeleton
git clone https://github.com/actionanand/angular-22.git --branch 1-skeleton new-proj-namenpx degit github:actionanand/angular-22#1-skeleton new-proj-namenpx gitpick https://github.com/actionanand/angular-22 -b 1-skeleton- Install the compatible node version
nvm install v24.16.0-
Install and Configure Prettier
- Install prettier as below:
npm install prettier -D
- Create a
.prettierrc.ymlfile and write down the format as below: - online ref
trailingComma: 'all' tabWidth: 2 useTabs: false semi: true singleQuote: true bracketSpacing: true bracketSameLine: true arrowParens: 'avoid' printWidth: 120 overrides: - files: - '*.js' - '*.jsx' options: bracketSpacing: true jsxSingleQuote: true semi: true singleQuote: true tabWidth: 2 useTabs: false - files: - '*.ts' options: tabWidth: 2
- Create a
.prettierignorefile and write as below(sample)
# Ignore artifacts: build coverage e2e node_modules dist dest reports # Ignore files *.lock package-lock.json yarn.lock
-
Install
Es Lint, if not installed
ng add @angular-eslint/schematicsif error comes, use the below command
ng add @angular-eslint/schematics@22.0.0
# or
ng add @angular-eslint/schematics@next- Configure pre-commit hooks
Pre-commit hooks are a nice way to run certain checks to ensure clean code. This can be used to format staged files if for some reason they weren’t automatically formatted during editing. husky can be used to easily configure git hooks to prevent bad commits. We will use this along with pretty-quick to run Prettier on our changed files. Install these packages, along with npm-run-all, which will make it easier for us to run npm scripts:
npm install -D husky pretty-quick npm-run-allTo configure the pre-commit hook, simply add a precommit npm script. We want to first run Prettier, then run TSLint on the formatted files. To make our scripts cleaner, I am using the npm-run-all package, which gives you two commands, run-s to run scripts in sequence, and run-p to run scripts in parallel:
"precommit": "run-s format:fix lint",
"format:fix": "pretty-quick --staged",
"format:check": "prettier --config ./.prettierrc --list-different \"src/{app,environments,assets}/**/*{.ts,.js,.json,.css,.scss}\"",
"format:all": "prettier --config ./.prettierrc --write \"src/{app,environments,assets}/**/*{.ts,.js,.json,.css,.scss}\"",
"lint": "ng lint",-
Initialize husky
- Run it once
npx husky init
- Add a hook
echo "npm run precommit" > .husky/pre-commit
- Make a commit
git commit -m "Keep calm and commit" # `npm run precommit and npm test` will run every time you commit
-
How to skip prettier format only in particular file
- JS
matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); // prettier-ignore matrix( 1, 0, 0, 0, 1, 0, 0, 0, 1 )
- JSX
<div> {/* prettier-ignore */} <span ugly format='' /> </div>
- HTML
<!-- prettier-ignore --> <div class="x" >hello world</div > <!-- prettier-ignore-attribute --> <div (mousedown)=" onStart ( ) " (mouseup)=" onEnd ( ) " ></div> <!-- prettier-ignore-attribute (mouseup) --> <div (mousedown)="onStart()" (mouseup)=" onEnd ( ) "></div>
- CSS
/* prettier-ignore */ .my ugly rule { }
- Markdown
<!-- prettier-ignore --> Do not format this- YAML
# prettier-ignore key : value hello: world
- For more, please check
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
ng generate component component-nameFor a complete list of available schematics (such as components, directives, or pipes), run:
ng generate --helpTo build the project run:
ng buildThis will compile your project and store the build artifacts in the dist/ directory. By default, the production build optimizes your application for performance and speed.
To execute unit tests with the Vitest test runner, use the following command:
ng testFor end-to-end (e2e) testing, run:
ng e2eAngular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
For more information on using the Angular CLI, including detailed command references, visit the Angular CLI Overview and Command Reference page.