Skip to main content

Workspace and project file structure of Angular

A workspace can be defined as a collection of files for one or more projects. A collection of projects makes up a workspace.

A project is the set of files that comprise a standalone application, a library or package, or a set of end-to-end tests.

In the creation of an Angular application, the Angular CLI command `ng new <project_name>` gets us started. When we run this command, the CLI installs the necessary Angular npm packages and other dependencies in a new workspace, with a root folder named project_name.

It also creates the following workspace and starter project files:

  • An initial skeleton app project (in the src/ subfolder).
  • An end-to-end test project (in the e2e/ subfolder).
  • Related configuration files.

The initial app project contains a simple welcome app, ready to run.

In this tutorial, we will explore the Angular file structure and the functions of some of these configuration files.


Workspace files

The top level of the workspace contains a series of workspace-wide configuration files.

Workspace Configuration FilesPurpose of the configuration file
.editorconfigConfiguration for code editors.
.gitignoreSpecifies intentionally untracked files that Git should ignore.
angular.jsonCLI configuration defaults for all projects in the workspace, including configuration options for build, serve, and test tools 
that the CLI uses, such as TSLint, Karma, and Protractor.
node_modulesProvides npm packages to the entire workspace.
package.jsonConfigures and keeps track of npm package dependencies that are available to all projects in the workspace.
package-lock.jsonProvides version information for all packages installed into node_modules by the npm client. If you use the yarn client,
this file will be yarn.lock instead.
tsconfig.jsonDefault TypeScript configuration for applications in the workspace, including TypeScript and Angular template compiler options.
tslint.jsonDefault TSLint configuration for apps in the workspace.
README.mdIntroductory documentation for the application

Default app project files

The CLI command `ng new my-app` creates a workspace folder named "my-app" and generates a new app skeleton. This initial app is the default app for CLI commands (unless you change the default after creating additional apps).

A newly generated app contains the source files for a root module, with a root component and template. When the workspace file structure is in place, you can use the `ng generate command` on the command line to add functionality and data to the initial app.

Besides using the CLI on the command line, you can also use an interactive development environment like Angular Console, or manipulate files directly in the app's source folder and configuration files.

The src/ subfolder contains the source files (app logic, data, and assets), along with configuration files for the initial app. Workspace-wide node_modules dependencies are visible to this project.

Application Source and 
Configuration Files
Purpose of the configuration files
.app/Contains the component files in which your app logic and data are defined.
.assets/Contains image files and other asset files to be copied as-is when you build your application.
environments/Contains build configuration options for particular target environments. By default, there is an unnamed standard development environment and 
a production ("prod") environment. You can define additional target environment configurations.
browserslistConfigures sharing of target browsers and Node.js versions among various front-end tools.
favicon.icoAn icon to use for this app in the bookmark bar.
index.htmlThe main HTML page that is served when someone visits your site. The CLI automatically adds all JavaScript and CSS files when building your app,
so you typically don't need to add any <script> or<link> tags here manually.
main.tsThe main entry point for your app. Compiles the application with the JIT compiler and bootstraps the application's root module (AppModule) to run in the browser.
You can also use the AOT compiler without changing any code by appending the -–aot flag to the CLI build and serve commands.
polyfills.tsProvides polyfill scripts for browser support.
styles.sassLists CSS files that supply styles for a project. The extension reflects the style preprocessor you have configured for the project.
test.tsThe main entry point for your unit tests, with some Angular-specific configuration. You don't typically need to edit this file.
tsconfig.app.jsonInherits from the workspace-wide tsconfig.json file.
tsconfig.spec.jsonInherits from the workspace-wide tsconfig.json file.
tslint.jsonInherits from the workspace-wide tslint.json file.



Comments

Popular

DOM(Document Object Model) and BOM(Browser Object Model)

DOM(Document Object Model) The DOM is the Document Object Model, which deals with the document, the HTML elements themselves, It organize the elements of the document in tree structure (DOM tree) and in the DOM tree, all elements of the document are defined as objects (tree nodes) which have properties and methods.When a web page is loaded, the browser creates a DOM tree for all the objects (Html elements) of that page. e.g. document and all traversal you would do in it, events, etc. A Simple DOM Tree BOM(Browser Object Model) The BOM is the Browser Object Model, which deals with browser components aside from the document,like history, location, navigator and screen (as well as some others that vary by browser). The Browser Object Model (BOM) in JavaScript includes the properties and methods for JavaScript to interact with the web browser. BOM provides you with window object, for example, to show the width and height of the window. It also includes the window.scre

JavaScript type hoisting with variable function Expression

JavaScript type hoisting with variable function Expression Hoisting is JavaScript default behavior to moving declaration on the top. Variable can be used before its declaration. To understand this, first we need to understand of hoist meaning, hoist means “raise(something) by means of ropes & pulleys”. now we can relate hoisting with JavaScript. JavaScript interpreter moves all declaration on the top at runtime. It is best practice to declare all variable at the top of their respective scopes. , JavaScript is loosely syntax language so it will not throw any error at runtime if the variable used before its declaration. But JavaScript does not allow variable used before its declaration in “use strict” mode. Example 1 In this example, we can see in a normal scenario, when y has declared & then used. in this case, it will give output 10 as excepted. <p id= "demo" ></p> <script> var y; //Declare y y = 10 ;

Life cycle hook

In Angular, every component has a life-cycle, a number of different stages it goes through. Creates the component Renders the component Creates and renders the component children Checks when the component data-bound properties change, and  Destroys the component before removing it from the DOM ngOnChanges this method is called  once  on component’s creation and then  every time changes  are detected in one of the component’s  input  properties. export class MyComponent implements OnChanges { ngOnChanges(changes: SimpleChanges) { // Insert Logic Here! } }   ngOnInit Invoked when given component has been initialized. This hook is only called  once  after the first  ngOnChanges export class MyComponent implements OnInit { ngOnInit() { // Insert Logic Here! } }     ngDoCheck Invoked when the change detector of the given component is invoked. It allows us to implement our own change detection algorithm for the given component. export class MyComponent implements D