A well-organizedenvironment with the right tools is the first step toward excellence and productivity; now, let’s set this environment up inyour workspace.
After installing Node.js following the instructions in theTechnical requirements section, the following tools and their plugins will help you inyour workflow.
VS Code
VS Code (https://code.visualstudio.com/) is currentlythe default tool for most developers, especially forfrontend projects.
There are other very good ones such as WebStorm (https://www.jetbrains.com/webstorm), but VS Code, with its plugins especially for Angular projects, facilitates great productivityand ergonomics.
To install the plugins listed here, in the code editor, click onExtensions or use the shortcutCtrl +Shift +X (Windows) orCmd +Shift +X (macOS).
The following are the VS Code plugins recommended for developingAngular applications.
Git Extension Pack
Git Extension Pack (https://marketplace.visualstudio.com/items?itemName=donjayamanne.git-extension-pack) isnotspecifically for developing Angular applications but it is useful for any kindof work.
Git is the default tool for version control and VS Code has native support for it. This set of plugins improves this support even further, adding the ability to read comments and changes made in previous commits in the editor, support for multiple projects, and a better view of your repository historyand logs.
Angular Language Service
TheAngular Language Service (https://marketplace.visualstudio.com/items?itemName=Angular.ng-template) extension ismaintained by the Angular team and adds support for most of the framework’s functionality right from thecode editor.
By adding this extension to your editor, it will have thefollowing features:
- Autocomplete in the HTML template file, allowing you to use component methods without having to consult theTypeScript file
- Checking for possible compilation errors in HTML template files andTypeScript files
- Quick navigation between HTML and TypeScript templates, allowing you to consult the definition of methodsand objects
This extension is also available for other IDEs such as WebStormand Eclipse.
Prettier
Prettier (https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) is a JavaScripttool that solvesthe code formatting problem. It is opinionated on formatting settings although some customizationis possible.
In addition to TypeScript, Prettier formats HTML, CSS, JSON, and JavaScript files, making this extension useful also for backend developmentusing Node.js.
To standardizeformatting across your entire team, you can install Prettier as a package for your project and run it on the project’s CI/CD track, which we’ll see inChapter 12,PackagingEverything – Best Practicesfor Deployment.
ESLint
When creating an application, the use of a linter is highly recommended to ensure good language practices and avoid errors from the beginningof development.
In the past, the default tool for linting TypeScript projectswasTSLint, but the project has beenabsorbed byESLint (https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint), which allows you to verify JavaScript andTypeScript projects.
With this extension, verification occurs quickly while you type the code of your project. ESLint can be installed as a package in your Angular project and thus performs this validation on the CI/CD conveyor of your project, whichwe will see inChapter 12,Packaging Everything – Best Practicesfor Deployment.
EditorConfig
TheEditorConfig (https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) plugin has the function of creating adefault configuration file for not only VS Code but also any IDE that supportsthis format.
This plugin is useful for standardizing things for your project and your team – for example, the number of spaces that eachTab key represents, or whether your project will usesingle quotes or double quotes torepresent strings.
To use it, just create or have a file named.editorconfig at the root of your project and VS Code will respect the settings described inthe file.
VS Code settings
VS Code, in addition to extensions, has severalnative settings that can help in your day-to-day work. By accessing theFile menu, we can activate the automatic saving flag so you don’t have to worry about pressingCtrl +S all the time (although this habit is already engraved in stone inour brains...).
Another interesting setting isZen mode, where all windows and menus are hidden so you can just focus on your code. To activate it, go toView |Appearance |Zen Mode, or use the keyboard shortcutCtrl +K +Z for Windows/Linux systems andCmd +K +Zfor macOS.
To improve the readability of your code during editing, an interesting setting isBracket coloring, which will give each parenthesis and bracket in your code adifferent color.
To enable this setting, open theconfiguration file using the shortcutCtrl +Shift +P for Windows/Linux orCmd +Shift +P for macOS and typeOpen UserSettings (JSON).
In the file, add thefollowing elements:
{ "editor.bracketPairColorization.enabled": true, "editor.guides.bracketPairs": true}VS Code also has theInlay Hints feature, which shows details of parameter types and return methods, as well as other useful information on the line you are reading inthe code.
To configure it in theSettings menu, look forInlay Hints and activate it if it is not already configured. For the development of your Angular application, you can also perform specific configurations byselectingTypeScript.
It is also possible to turn on this functionality by directly configuring thesettings.json filewith thefollowing elements:
{ "typescript.inlayHints.parameterNames.enabled": "all", "typescript.inlayHints.functionLikeReturnTypes.enabled": true, "typescript.inlayHints.parameterTypes.enabled": true, "typescript.inlayHints.propertyDeclarationTypes.enabled": true, "typescript.inlayHints.variableTypes.enabled": true, "editor.inlayHints.enabled": "on"}Fira Code font and ligatures
An important detail thatnot every developer pays attention to is the type of font they use in their code editor. A confusing font can make it difficult to read code and tireyour eyes.
The ideal option is to use monospaced fonts, that is, fonts where the characters occupy the samehorizontal space.
A very popularfont isFira Code (https://github.com/tonsky/FiraCode), which, in addition to being monospaced, has ligatures for programming – that is, joining or changing characters that represent symbols such as==,>=, and=>, as shown in thefollowing figure:
Figure 1.1 – Example of symbols with font ligatures
After installing the font on your operating system, to enable ligatures in the font in VS Code, access theconfiguration file as in the previous section and add thefollowing elements:
{ "editor.fontFamily": "Fira Code", "editor.fontLigatures": true,}Standardizing the extensions and settings in the project
In theWhy choose Angular? section, we learned that one of the advantages of choosing this framework for your project is the standardization it provides to development andthe team.
You can also standardize your VS Code settings and record them in your Git repository so that not only you but also our team can have that leapin productivity.
To do this, in your repository, create a folder called.vscode, and inside that folder, create two files. Theextensions.json file will have all the extensions recommended by the project. In this example, we will use the extensions wesaw earlier:
{ "recommendations": [ "dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "Angular.ng-template", "donjayamanne.git-extension-pack", "editorconfig.editorconfig" ] }Let’s also create thesettings.json file, which allows you to add VS Code settings to your workspace. These settings take precedence over user settings and VS Code’sdefault settings.
This file will have thepreviouslysuggested settings:
{ "editor.bracketPairColorization.enabled": true, "editor.guides.bracketPairs": true "editor.fontFamily": "Fira Code", "editor.fontLigatures": true, "typescript.inlayHints.parameterNames.enabled": "all", "typescript.inlayHints.functionLikeReturnTypes.enabled": true, "typescript.inlayHints.parameterTypes.enabled": true, "typescript.inlayHints.propertyDeclarationTypes.enabled": true, "typescript.inlayHints.variableTypes.enabled": true, "editor.inlayHints.enabled": "on"}By synchronizing these files in your repository, when your team members download the project and open VS Code for the first time, the following messagewill appear:
Figure 1.2 – VS Code prompt for recommended extensions
Once confirmed, all the extensions configured in the file will be installed in the VS Code development environment of your team members, thus automating the task of standardizing the team’swork environment.
Angular DevTools
One tool missing from the Angular framework was a way to drill down into an application in the browser. Browsers such as Chrome and Firefox have greatly improved the developer experience over the years, broadly for all typesof websites.
With that in mind, the Angular team, starting from version 12, created the Angular DevTools extension for Chromeand Firefox.
To install it, you need to go to the extension store of the browser (Chrome or Firefox) and clickonInstall.
With it installed, access to the site built with Angular, and with the build set up for development, theAngular tab will appear in thedeveloper tools:
Figure 1.3 – Angular DevTools Chrome extension example
Thistool allows you to browse the structure of your app, locate the code of the components on the screen, and profile your application to detect possible performance problems.
Now you have a productive development environment for developing Angular applications, we are ready to startour application.