Git Product home page Git Product logo

angular-starter's Introduction

Angular starter

Starter project for stand-alone Angular applications.


Table of Contents


Angular

The project has been created with Angular 10 in strict mode and tuned to make it stricter. The module target is esnext which means that features that are on the standard track but are not in an official ES spec yet are available for development and polyfilled automatically.


NPM

Some scripts are available just as a starting point. As a bonus, source-map-explorer is available for inspecting the bundle size.

The dependencies get installed with the exact version. This will avoid any problems with package versions and you will know exactly what you want to be installed and what gets actually installed.


Unit Testing

Jest and Spectator have been configured for unit testing. Also some additional libraries like ng-mocks and mockdate are also installed. The first one works pretty well with Spectator and the second excels at mocking Date objects.


Linting & Formatting

All the files are being linted, fixed and formatted with Prettier in a precommit hook (thanks to Husky and Lintstaged), also available through npm scripts and integrated with VSCode, so when a file is saved, it is linted, fixed and formatted automatically. No more manual formatting of the code!

TypeScript files:

Linted with Eslint. Plugins being used:

  • @typescript-eslint. ESLint rules support for TypeScript.
  • @angular-eslint. Specific rules for Angular.
  • import. Sorts import statements in different groups.
  • unicorn. Set of best practices rules.
  • compat. Checks compatibility of ECMAScript features with the supported browsers.
  • prettier. Support for Prettier formatting.
  • jest. Support for Jest files.

SCSS files:

Linted with Stylelint. Plugins being used:

  • stylelint-config-standard. Set of best practices rules.
  • stylelint-config-prettier. Support for Prettier formatting.
  • stylelint-order. Sorts rules.
  • stylelint-scss. Specific rules for SCSS.
  • stylelint-no-unsupported-browser-features. Checks compatibility of CSS features with the supported browsers.

HTML files:

Formatted with JS Beautify.


TypeScript path aliases

In order to work properly with the eslint-plugin-import and to avoid naming collisions, path aliases cannot be formed like organization-scoped packages, eg. @feature, otherwise the plugin will sort in the same group custom path aliases and third-party modules.

Path aliases in this case are start with @/, eg. @/feature. Directories inside src/app are directly mapped into a path alias with the same name. For instance, if we have this directory structure:

src
 └ app
   ├ feat1
   │   ...
   └ feat2
       ...

There will be these aliases created automatically:

@/feat1
@/feat2

This will be the result after the plugin eslint-plugin-import do its job:

import {
  createComponentFactory,
  mockProvider,
  Spectator
} from '@ngneat/spectator/jest';

import { ApiService } from '@/feat1/services/api.service';
import { DateService } from '@/feat2/services/date.service';

import { FirstComponent } from './first.component';

Marvelous! In a quick look we can distinguish between third-party modules, feature modules (path-aliased) and imports from the current feature module.


VSCode

VSCode has been integrated with the linting and formatting project settings so each time a file is saved allt he magic will happen.

There also extensions that needs to be installed. Just open the project and you will be prompted with a message to install them. They are listed in the .vscode/extensions.json file. Some of them are required but others are highly recommended.


Known issues

  • @ngneat/[email protected] has an explicit dependency with Jasmine types when type-checking Jest spec files, that's why the library is patched in a postinstall hook to remove this dependency.

angular-starter's People

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.