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

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 ; ...

JavaScript Closure

What is closure? It is my personal experience, I have never understood closure, I have read many articles & have seen many videos. Finally, I understood sometimes we even used a closure without realizing we were using a closure. First, understand the meaning of closure “an act or process of closing something”, now we can relate closure in javascript, closure is an inner function which wraps inside the outer function, which can access outer function scope & global function scope. for scoping you can read my previous blog:- http://uisource.blogspot.com/2018/08/javascript-variable-scoping.html why do we create? Global variables can be made local (private) with closures. To avoid the usage of global variables, use the local variables and wrap your code in the closure. A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain(Lexical scoping). The closure has three scope chains: it has access to its own scope (variables define...

JavaScript Variable Scoping

There are two types of variables in JavaScript.  Global variables have global access and are declared outside of any function. Local variables are those declared inside of function. Lexical Scoping(Nested JavaScript Function) means that in a nested group of functions, the inner functions have access to the variables and other resources of their parent scope. Global variable:- Global variable declares & initialize outside the function, & accessible in from anywhere in the code. The global variable always stored in memory even function execution finish, it always keeps in memory or always accessible from anywhere in the code. Example 1 var message= "hello i am global variable" ; //global variable function a (){ console.log(message); // output: hello i am global variable } function b (){ console.log(message); // output: hello i am global variable } function a() function b() In above example message is a global variab...