-
Notifications
You must be signed in to change notification settings - Fork 0
Angular project setup guide
- Node.js (LTS version)
- Pick a project name (typically same as repository name, e.g.
flowup-web) and short vendor prefix (e.g.fu). - Run
npx ng new <project-name> --prefix=<prefix> --routing --strict --style=scss.- These flags set a selector prefix, include routing setup, set strict TypeScript compilation flags, and set up SCSS instead of CSS (see CLI reference for all available options).
- You can leave out
npxin the above command if you've installed the Angular CLI globally, but first make sure it's up-to-date withnpm i -g @angular/cli@latest(usesudoprefix on Unix systems).
- Verify setup by starting local development server with
ng serve(ornpm start) and visit http://localhost:4200/ in a browser. - Optionally, you may also verify production build by running
ng build --prodand then previewing resulting bundle vianpx lite-server --baseDir=dist/<project-name>.
The following recommendations may not apply to all projects, so discuss with your teammates first if they're appropriate for your needs.
- Modify
styles.scssto include the following CSS reset. - In order to import SCSS variables without using relative paths (e.g.
import 'variables'instead ofimport '../../../variables'), pick a styles directory (e.g.srcorsrc/styles) and runng config projects.<project-name>.architect.build.options.stylePreprocessorOptions.includePaths[0] <styles-directory>(or modifyangular.jsondirectly by adding"stylePreprocessorOptions": { "includePaths": ["<styles-directory>"] }). If you then create a file named_variables.scssin the chosen directory, it may be imported as described above.
- To optimize for performance, it is recommended to use the OnPush change detection strategy. Modify your existing components by adding
changeDetection: ChangeDetectionStrategy.OnPushto their@Componentdecorator and ensure all generated components include it by default viang config projects.<project-name>.schematics.@schematics/angular:component.changeDetection OnPush(or modifyingangular.jsondirectly). - Feel free to customize schematics further based on your preferences (e.g. avoid generating component
.spec.tsfiles by settingng config projects.<project-name>.schematics.@schematics/angular:component.skipTests true). Look upangular.jsonschema for all available options.
- The Angular CLI already integrates TSLint (with the Angular-specific codelyzer plugin and a default set of rules).
- In order to customize the lint rules according to our recommendations, perform the following steps:
- install the tslint-immutable rules preset with
npm i -D tslint-immutable, - install the rxjs-tslint plugin with
npm i -D rxjs-tslint, - copy the company standard
tslint.jsonfile (feel free to suggest changes here 🙂) and replace occurences of"fu"with your own prefix, - fix (or explicitly ignore) errors that may be reported by
ng lint(e.g. add// tslint:disable-next-line:no-import-side-effectbefore Zone.js imports).
- install the tslint-immutable rules preset with
- If your team wants to lint stylesheets, you can integrate stylelint by:
- installing the package via
npm i -D stylelint, - copying the company standard
.stylelintrc.jsonfile (feel free to suggest changes here 🙂), - adding the following script to your
package.json:"stylelint": "stylelint \"src/**/*.scss\"".
- installing the package via
In order to automate code formatting using Prettier, follow steps from our guide.
If your team wishes to write unit tests, we recommend Jest over Karma & Jasmine. This article provides instructions on migrating to Jest (you'll probably also want to set esModuleInterop and allowJs flags in compilerOptions in your tsconfig.spec.json).
To trigger commands to run on (and potentially block) specific Git operations (e.g. commit, push), you may integrate Husky. See our guide for an example setup, but discuss which options actually make sense for your team. Common tasks include running linters, tests, formatters or code generators.
Here are instructions on setting up some common libraries that you may wish integrate in your project using the Angular CLI.
ng add @ngrx/store@latest
ng add @ngrx/store-devtools
ng add @ngrx/effects
ng add @angular/fire
ng add @angular/material
ng add apollo-angular