mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
Additions/52 lazy load component (#963)
* feat: create challenge 52 on lazy load component Initial boilerplate from `nx g @angular-challenges/cli:challenge` * feat: revert to NgModule Copy of 31 * feat: initial version of starting point * feat: add documentation * feat: pr tweaks Add author file Remove thomas from the contributor list Add a more direct hint * feat: pr tweaks Update "Go to the latest Challenge" link
This commit is contained in:
36
apps/angular/52-lazy-load-component/.eslintrc.json
Normal file
36
apps/angular/52-lazy-load-component/.eslintrc.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"extends": ["../../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
],
|
||||
"rules": {
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "attribute",
|
||||
"prefix": "app",
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"extends": ["plugin:@nx/angular-template"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
13
apps/angular/52-lazy-load-component/README.md
Normal file
13
apps/angular/52-lazy-load-component/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# lazy-load-component
|
||||
|
||||
> author: thomas-laforge
|
||||
|
||||
### Run Application
|
||||
|
||||
```bash
|
||||
npx nx serve angular-lazy-load-component
|
||||
```
|
||||
|
||||
### Documentation and Instruction
|
||||
|
||||
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/angular/52-lazy-load-component/).
|
||||
22
apps/angular/52-lazy-load-component/jest.config.ts
Normal file
22
apps/angular/52-lazy-load-component/jest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'angular-lazy-load-component',
|
||||
preset: '../../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
coverageDirectory: '../../../coverage/apps/angular/52-lazy-load-component',
|
||||
transform: {
|
||||
'^.+\\.(ts|mjs|js|html)$': [
|
||||
'jest-preset-angular',
|
||||
{
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||
},
|
||||
],
|
||||
},
|
||||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
||||
snapshotSerializers: [
|
||||
'jest-preset-angular/build/serializers/no-ng-attributes',
|
||||
'jest-preset-angular/build/serializers/ng-snapshot',
|
||||
'jest-preset-angular/build/serializers/html-comment',
|
||||
],
|
||||
};
|
||||
79
apps/angular/52-lazy-load-component/project.json
Normal file
79
apps/angular/52-lazy-load-component/project.json
Normal file
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"name": "angular-lazy-load-component",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/angular/52-lazy-load-component/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/angular/52-lazy-load-component",
|
||||
"index": "apps/angular/52-lazy-load-component/src/index.html",
|
||||
"browser": "apps/angular/52-lazy-load-component/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/angular/52-lazy-load-component/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": [
|
||||
"apps/angular/52-lazy-load-component/src/favicon.ico",
|
||||
"apps/angular/52-lazy-load-component/src/assets"
|
||||
],
|
||||
"styles": ["apps/angular/52-lazy-load-component/src/styles.scss"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "angular-lazy-load-component:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "angular-lazy-load-component:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "angular-lazy-load-component:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/angular/52-lazy-load-component/jest.config.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
apps/angular/52-lazy-load-component/src/app/app.component.ts
Normal file
22
apps/angular/52-lazy-load-component/src/app/app.component.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Component, signal } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<div class="h-screen bg-gray-500">
|
||||
@if (topLoaded()) {
|
||||
<app-top />
|
||||
} @else {
|
||||
<app-placeholder />
|
||||
<button
|
||||
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
|
||||
(click)="topLoaded.set(true)">
|
||||
Load Top
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
export class AppComponent {
|
||||
topLoaded = signal(false);
|
||||
}
|
||||
12
apps/angular/52-lazy-load-component/src/app/app.module.ts
Normal file
12
apps/angular/52-lazy-load-component/src/app/app.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app.component';
|
||||
import { PlaceholderComponent } from './placeholder.component';
|
||||
import { TopComponent } from './top.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [AppComponent, PlaceholderComponent, TopComponent],
|
||||
imports: [BrowserModule],
|
||||
bootstrap: [AppComponent],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-placeholder',
|
||||
template: `
|
||||
I'm a placeholder component.
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: grid;
|
||||
padding: 20px;
|
||||
background-color: #f0f0f0;
|
||||
height: 50%;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class PlaceholderComponent {}
|
||||
17
apps/angular/52-lazy-load-component/src/app/top.component.ts
Normal file
17
apps/angular/52-lazy-load-component/src/app/top.component.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-top',
|
||||
template: `
|
||||
I am a very heavy, expensive component that should be lazy loaded.
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: grid;
|
||||
padding: 20px;
|
||||
background-color: #f0f0f0;
|
||||
height: 50%;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class TopComponent {}
|
||||
BIN
apps/angular/52-lazy-load-component/src/favicon.ico
Normal file
BIN
apps/angular/52-lazy-load-component/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/angular/52-lazy-load-component/src/index.html
Normal file
13
apps/angular/52-lazy-load-component/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>angular-lazy-load-component</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
6
apps/angular/52-lazy-load-component/src/main.ts
Normal file
6
apps/angular/52-lazy-load-component/src/main.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
import { AppModule } from './app/app.module';
|
||||
|
||||
platformBrowserDynamic()
|
||||
.bootstrapModule(AppModule)
|
||||
.catch((err) => console.error(err));
|
||||
5
apps/angular/52-lazy-load-component/src/styles.scss
Normal file
5
apps/angular/52-lazy-load-component/src/styles.scss
Normal file
@@ -0,0 +1,5 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
2
apps/angular/52-lazy-load-component/src/test-setup.ts
Normal file
2
apps/angular/52-lazy-load-component/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
14
apps/angular/52-lazy-load-component/tailwind.config.js
Normal file
14
apps/angular/52-lazy-load-component/tailwind.config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind');
|
||||
const { join } = require('path');
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
|
||||
...createGlobPatternsForDependencies(__dirname),
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
10
apps/angular/52-lazy-load-component/tsconfig.app.json
Normal file
10
apps/angular/52-lazy-load-component/tsconfig.app.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"types": []
|
||||
},
|
||||
"files": ["src/main.ts"],
|
||||
"include": ["src/**/*.d.ts"],
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
6
apps/angular/52-lazy-load-component/tsconfig.editor.json
Normal file
6
apps/angular/52-lazy-load-component/tsconfig.editor.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {},
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
33
apps/angular/52-lazy-load-component/tsconfig.json
Normal file
33
apps/angular/52-lazy-load-component/tsconfig.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"useDefineForClassFields": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.editor.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
15
apps/angular/52-lazy-load-component/tsconfig.spec.json
Normal file
15
apps/angular/52-lazy-load-component/tsconfig.spec.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node", "@testing-library/jest-dom"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": [
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts",
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user