Workspace and project file structure
You develop angular apps in the context of an Angular workspace. A workspace contains the files for one or more projects. A project is the set of files that comprise a standalone app, a library, or a set of end-to-end (e2e) tests.
The Angular CLI command ng new <project_name> gets you started. When you 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, also called project_name (in the src/ subfolder).
- An end-to-end test project (in the e2e/ subfolder)./li>
- Related configuration files.
The initial app project contains a simple Welcome app, ready to run.
Workspace files
The top level of the workspace contains a number of workspace-wide configuration files which includes.
WORKSPACE CONFIG FILES | PURPOSE |
---|---|
.editorconfig | Configuration for code editors. See EditorConfig. |
.gitignore | Specifies intentionally untracked files that Git should ignore. |
angular.json | CLI 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_modules | Provides npm packages to the entire workspace. |
package.json | Configures npm package dependencies that are available to all projects in the workspace. |
package-lock.json | Provides 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.json | Default TypeScript configuration for apps in the workspace, including TypeScript and Angular template compiler options. |
tslint.json | Default TSLint configuration for apps in the workspace. |
README.md | Introductory documentation. |
All projects within a workspace share a CLI configuration context. Project-specific TypeScript configuration files inherit from the workspace-wide tsconfig.*.json, and app-specific TSLint configuration files inherit from the workspace-wide tslint.json.
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.
APP SOURCE & CONFIG FILES |
PURPOSE |
app/ |
Contains the component files in which your app logic and data are defined. See details in App source folder below. |
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. |
browserslist |
Configures sharing of target browsers and Node.js versions among various front-end tools. |
favicon.ico |
An icon to use for this app in the bookmark bar. |
index.html |
The 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.ts | The 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.ts |
Provides polyfill scripts for browser support. |
styles.sass |
Lists CSS files that supply styles for a project. The extension reflects the style preprocessor you have configured for the project. |
test.ts |
The main entry point for your unit tests, with some Angular-specific configuration. You don't typically need to edit this file. |
tsconfig.app.json |
Inherits from the workspace-wide tsconfig.json file. |
tsconfig.spec.json |
Inherits from the workspace-wide tsconfig.json file. |
tslint.json |
Inherits from the workspace-wide tslint.json file. |
Previous: Internationalization (i18n)
Next:
Dependency Injection in Action
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/angular/workspace-and-project-file-structure.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics