Git Product home page Git Product logo

extreme-angular's Introduction

Extreme Angular 17

image

This is an opinionated Angular starter project that enforces best practices and provides a robust foundation for building modern, accessible web applications using Angular and its ecosystem of tools and libraries. Please feel free to use this as-is, or as inspiration, for your next Angular project ❀️

You can run and explore extreme-angular on StackBlitz: https://stackblitz.com/github/joematthews/extreme-angular?preset=node

Note

If you run into any issues at all with installing, updating, or using extreme-angular, then please search through the issues. If you do not see a similar issue, then please create a new issue -- thank you! πŸ™

Table of Contents

Installation & Starting

These instructions assume you have installed git version control and the latest version of Node.js LTS.

To create a new project, I recommend cloning only the most recent commit and renaming the remote branch to 'upstream'. (Replace new_project_name with the name of your project):

git clone --depth=1 --origin=upstream [email protected]:joematthews/extreme-angular.git new_project_name

Change to the new project directory and install the dependencies:

cd new_project_name
npm install

Use the shortcut CTRL+SHIFT+H in VSCode to search and replace extreme-angular with your chosen project name.

To start the development server run npm start.

Note

If you're using VSCode and Chrome, then press F5 on the keyboard to start the app in debug mode.

Key Features

The goal of these changes is to enforce 'best practices' while still being 100% compatible with the latest Angular documentation.

Accessibility (a11y)

extreme-angular enables all of the accessibility rules from angular-eslint by default including image alt text, form labels, no autofocus, valid ARIA, and more.

In my experience these rules are easy to work with if enabled early in the development process and early adoption of these rules is also very helpful for avoiding common accessibility anti-patterns.

If you run into a problem with any of these accessibility rules I encourage you to open up an issue so we can troubleshoot the the errors or concerns together.

For a full list of accessibility-centric rules, check out the angular-eslint template rules

The Accessibility in Angular guide is a great place to start learning about accessibility in Angular and it provides resources on the topic of accessibility.

Please let me know if more can be done to improve the accessibility of extreme-angular by creating an issue. Thank you.

Internationalization (i18n)

Enables Internationalization and requires i18n attributes on all elements that include text.

Although you may not require internationalization capabilities right now, adding i18n attributes as-you-go may make it less painful to use internationalization in the future.

To disable i18n enforcement, set "@angular-eslint/template/i18n" to "off" within the *.html section of the .eslintrc.json file:

"rules": {
  "@angular-eslint/template/i18n": "off"
}

Note

Saving a document using VSCode will automatically add missing i18n attributes using eslint --fix.

Angular Material & Dark Theme

Enables Angular Material and uses a dark theme that automatically switches from dark to light based on the light/dark preference set in the OS. The default theme is dark.

Changes density to -2 to make the UI (including buttons) more compact and more inline with web expectations.

Downloads the Roboto font from the Google font api in the index.html file. The font is set in the styles.scss file.

Enables Animations for Angular Material and custom components.

Server-side-rendering & Pre-rendering

Enables Server-side-rendering and pre-rendering to improve SEO and user experience. To start the SSR server run the following commands:

npm run build
npm run serve:ssr:new_project_name

Note

Replace new_project_name above with the name of your project.

Typescript

Adds the following compiler options to the tsconfig.json file to help with writing cleaner code:

Prettier

Uses Prettier to provide opinionated formatting so diffs contain less formatting changes and teams argue less about formatting in general.

In the .prettierrc.json file, htmlWhitespaceSensitivity is set to ignore to improve the formatting of templates. This will trim whitespace around and inside elements. Use   (non-breaking space) to explicitly enforce spacing between inline-elements.

The following prettier plugins are used:

Use npm run format to format all relevant files within the project.

Eslint

The .eslintrc.json file is set up to use overrides for each of the following file types: *.js, *.ts, *spec.ts, *.html, *.json, and *.md.

To help ensure all project files are linted, the following eslint plugins are used:

Use npm run lint to lint all relevant files within the project.

Stylelint

Uses Stylelint to lint CSS and SCSS using the stylelint-config-standard and stylelint-config-standard-scss configurations.

Rules for stylelint are split between *.css & *.scss overrides and can be modified in the .stylelintrc.json file.

Use npm run lint:style to lint all styles within the project.

VSCode

Recommends VSCode extensions for Angular, Editorconfig, Prettier, Eslint, Stylelint, Code Spell Checker, Intellicode, and Intellicode Completions automatically via a pop-up when the project is opened for the first time. These recommendations are set in the .vscode/extensions.json file.

Configures the following settings in the .vscode/settings.json file:

  • Sets Prettier as default formatter
  • Formats code, and fix linting errors (if possible), on save with CTRL+S or via the menu.
  • Auto saves after 2 seconds (does not automatically format code or fix errors)

Code Spell Checker

Enables spell checking for all project files.

Add project specific words to .cspell.json.

I highly recommend installing Code Spell Checker for VSCode. With this extension you can select "Add to config: .cspell.json" from the 'Quick Fix' menu of misspelled words.

Use npm run check-spelling to look for misspelled words in the project.

Commitizen & Commitlint

Uses Commitizen to suggest consistent formatting of commit messages.

On git commit, a interactive prompt will appear:

? Select the type of change that you're committing: (Use arrow keys)
❯ feat:     A new feature
  fix:      A bug fix
  docs:     Documentation only changes
  style:    Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  refactor: A code change that neither fixes a bug nor adds a feature
  perf:     A code change that improves performance
  test:     Adding missing tests or correcting existing tests

Uses Commitlint and @commitlint/config-conventional to enforce good commit messages. Commitlint can be configured in commitlint.config.js.

Husky & Lint-staged

Uses Husky to manage the pre-commit, pre-push, prepare-commit-msg, and commit-msg git hooks.

Uses Lint-staged to run prettier, eslint, stylelint, cspell, and tsc-files against all staged files before committing to git.

Runs npm run test:ci before each push.

Runs commitizen wizard in the prepare-commit-msg hook and runs commitlint in the commit-msg hook.

Notes directory

Files in the ./notes directory are ignored by git but are searchable within VSCode.

This may be useful for keeping personal markdown files for notes or reference including:

  • Notes about clients
  • Todo lists
  • Code snippets & notebooks (iTypescript, tslab, etc)

Updating

Caution

Depending on the maturity of your project, it may be better to look at the release notes and commits and manually make changes instead of merging. If the Angular version has changed, then follow the instructions to update Angular first before attempting to merge or make changes.

To pull in the latest changes, I recommend checking out a 'update' branch and merging the latest changes from upstream/main:

git checkout main && git pull
git checkout -b update
git merge upstream/main

You may have to resolve merge conflicts. After a successful merge, install dependencies and then format, lint, test, and fix any new errors for all files:

npm install
npm run format
npm run lint
npm run lint:style
npm run test

Merge the update branch back into the main branch:

git checkout main && git pull
git merge update

Finally, delete the update branch:

git branch -d update

Tips & Tricks

These are tips and tricks I feel are too opinionated to include in the repository. If this section gets out of hand I will probably move it into a separate repository.

NestJS

If you are looking for a full featured, robust, and enterprise-ready Typescript backend framework that pairs well Angular, then checkout the NestJS web framework project. NestJS has features similar to Spring Boot, .NET and other enterprise web frameworks.

Inlay Hints

I highly recommend enabling inlay hints in VSCode. They give me the confidence to use Typescript's type inference without feeling the need specify types 'for visibility'.

Add the following to your user settings to enable inlay hints for javascript & typescript:

{
  "editor.inlayHints.enabled": "onUnlessPressed",
  "javascript.inlayHints.enumMemberValues.enabled": true,
  "javascript.inlayHints.functionLikeReturnTypes.enabled": true,
  "javascript.inlayHints.parameterNames.enabled": "all",
  "javascript.inlayHints.parameterTypes.enabled": true,
  "javascript.inlayHints.propertyDeclarationTypes.enabled": true,
  "javascript.inlayHints.variableTypes.enabled": true,
  "typescript.inlayHints.enumMemberValues.enabled": true,
  "typescript.inlayHints.functionLikeReturnTypes.enabled": true,
  "typescript.inlayHints.parameterNames.enabled": "all",
  "typescript.inlayHints.parameterTypes.enabled": true,
  "typescript.inlayHints.propertyDeclarationTypes.enabled": true,
  "typescript.inlayHints.variableTypes.enabled": true
}

Use CTRL + ALT (or CTRL + OPTION on Mac) to temporarily disable hints -- Or, change editor.inlayHints.enabled to offUnlessPressed to reverse this behavior.

Font Ligatures

VSCode is capable of using 'font ligatures' -- not everyone likes font ligatures, but I really enjoy them.

The two most popular fonts that support font ligatures are Fira Code and Jet Brains Mono. I typically use the 'Regular' *.ttf variant of each font.

After you've downloaded and installed the font of your choice, you can set the font and enable font ligatures in your settings:

{
  "editor.fontFamily": "'Fira Code', Menlo, Monaco, 'Courier New', monospace",
  "editor.fontLigatures": true
}

These are excellent fonts for readability even if you choose to leave editor.fontLigatures disabled.

The fira code repository maintains a list of alternative fonts with ligatures.

Catppuccin

Looking for a new theme to try? Catppuccin is great theme that I describe as 'modern Darcula'.

Catppuccin has 4 flavours: 🌻 Latte, πŸͺ΄ FrappΓ©, 🌺 Macchiato, & 🌿 Mocha.

Catppuccin is everywhere. I also use it for my macOS terminal theme.

VSCode has two extensions: Catppuccin for VSCode and Catppuccin Icons for VSCode.

My favorite is πŸͺ΄ FrappΓ©.

extreme-angular's People

Contributors

hkbertoson avatar joematthews avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

extreme-angular's Issues

cspell should target src directory only

I thought it would be helpful to have cspell check all files but the options are not really there to ignore specific files, like package.json, .gitignore etc etc. So the words list was filling up which just seems off for a template project...

Targeting the src/ directory only seems to be what most teams may actually want spell checking for -- even though it would be nice to spell check readme and other markdown files on pre-commit, the extension can still show errors, notot commiting src with obvious misspellings is the focus I think.

@angular-devkit/build-angular has webpack-dev-middleware dependency vunerability

Tracking npm audit message:

webpack-dev-middleware  6.0.0 - 6.1.1
Severity: high
Path traversal in webpack-dev-middleware - https://github.com/advisories/GHSA-wr3j-pwj9-hqq6
fix available via `npm audit fix --force`
Will install @angular-devkit/[email protected], which is a breaking change
node_modules/webpack-dev-middleware
  @angular-devkit/build-angular  15.1.0-next.0 - 17.3.1
  Depends on vulnerable versions of webpack-dev-middleware
  node_modules/@angular-devkit/build-angular

GHSA-wr3j-pwj9-hqq6

npm audit fix --force would downgrade @angular-devkit/build-angular to version of 15 that is not affected, which is not acceptable.

Fixes are in place and will be release soon: angular/angular-cli#27334

Should commitizen be opt-in?

I think commitizen is great for individuals and teams that want to acquaint themselves with convention commits.

In exteme-angular you can omit the message of a commit (git commit) and commitizen will prompt with a interactive CUI guiding you thru how to create a conventional commit.

However, when committed with a well formed convention commit message, The user can use CTRL-C to skip commitizen and use the commit message (but this is communicated in the prompt at all. Also commitizen does not report the commit message after completing the prompts.

I do see value in commitizen, but should should it be disabled by default, or removed, in favor of clarity and then rely solely on commitlint to report missing convention commit message components?

Getting [WARNING] bundle initial exceeded maximum budget

At some point I noticed the initial budget exceeded the default of 500kb. Currently, the extreme-angular starter project builds at 509.91 kB for all total assets, ~106kb when gzipped.

This at first looked very high, but after some investigation I've discovered these contribute to a significant portion:

  • Animations module
  • Angular Material theme (theme.scss)
  • Any Material component

I think these features add a lot of power/value up front and I want to keep them in the project. Enterprise, opinionated frameworks are robust and that comes at some cost.

I do not suspect this will balloon out of control for most projects because this cost is up front, and additional components are far less significant if standalone imports are audited routinely.

bundle initial exceeded maximum budget

I noticed that the 'bundle initial' size increased beyond 500kb after implementing this fix #26

I find it odd that updating @types/node increased the size past Angular's default limit. I'm not sure if this is a problem at all, I just find it odd.

Is 700kb a better max 'budget initial'? Or is that too low for real work in Angular?

If you have insight then please let me know.

Angular Schematic for extreme-angular

extreme-angular is all the best practices and configurations I have accumulated over the years into one succinct starter project. I think it fulfills that purpose.

There may be a way turn extreme-angular into an Angular Schematic which is currently out of scope of my day-to-day work so I have not needed to learn it until now.

When my workload lightens a little bit I plan to dig into schematic authoring so I can figure some of this stuff out.

eslint errors in server.ts

The following eslint errors were missed when adding additional rules:

➜  extreme-angular git:(main) npm run lint

> lint
> eslint "**/*.{js,ts,html,json,md}"


/Users/joe/Code/extreme-angular/server.ts
  38:31  error  Invalid type "string | undefined" of template literal expression  @typescript-eslint/restrict-template-expressions
  43:15  error  Prefer the safe `: unknown` for a catch callback variable         @typescript-eslint/use-unknown-in-catch-callback-variable
  57:70  error  Invalid type "string | 4000" of template literal expression       @typescript-eslint/restrict-template-expressions

/Users/joe/Code/extreme-angular/src/main.ts
  7:54  error  Prefer the safe `: unknown` for a catch callback variable  @typescript-eslint/use-unknown-in-catch-callback-variable

βœ– 4 problems (4 errors, 0 warnings)

Angular 17.2 does not work with Stackblitz

Tracking: stackblitz/webcontainer-core#1331

Currently a fresh-new Angular 17.2 project will not work with Stackblitz. Stackblitz is aware and tracking it. Click on the issue above and give it a πŸ‘ if you need to run extreme-angular (or any Angular 17.2 project) on Stackblitz.

Soon, I hope, I will be able to add a Stackblitz link at the top of the README.md for extreme-angular. I had to remove it after updating to 17.2.

Cannot search within /notes directory using vscode

Need to add the following to .vscode/settings.json to enable searching within the ignored notes/ directory:

"search.useIgnoreFiles": true

Typically, this setting is used to ignore files from search that specified in .ignore. But since I specified !/notes within .ignore, then vscode will search within /notes even though it is ignored in .gitignore -- does your brain hurt? mine too.

follow-redirects has moderate vunerability

npm audit shows follow-redirects has a vunerability:

follow-redirects  <=1.15.5
Severity: moderate
follow-redirects' Proxy-Authorization header kept across hosts - https://github.com/advisories/GHSA-cxjh-pqwp-8mfp
fix available via `npm audit fix`
node_modules/follow-redirects

GHSA-cxjh-pqwp-8mfp

Better looking app.component template

First impressions are not everything, but I think they have a lasting impact.

I would very much appreciate a "designer's touch" for the app.component.html. πŸ™

Maybe the new page shows off the auto-switching black theme included for Angular Material?

Ideally, the new page does not require additional dependencies πŸ˜“.

Perhaps a screenshot of the better looking app.component can be used at the top of the README.md in place of the 'hero-meme' 🀣

Use separate files for templates and styles

I think inlineTemplate and inlineStyle may as default may be a bit premature. Looking back, I think I gravitated towards this preference because Angular 17's new documentation uses inline templates in the interactive examples.

Although tooling for inline templates appears to be fine, I am noticing issues getting stylelint and prettier to recognize both the array-form and string-literal form of the inline styles property for @Component.

I may revisit inline templates and styles in the future, but for now, I will keep them as separate files.

Making a PR now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.