Skip to content

Commit 9128b99

Browse files
committed
feat: initial version
0 parents  commit 9128b99

27 files changed

+13041
-0
lines changed

.eslintrc.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"root": true,
3+
"parserOptions": {
4+
"ecmaVersion": "latest"
5+
},
6+
"env": {
7+
"es6": true
8+
},
9+
"plugins": [
10+
"simple-import-sort"
11+
],
12+
"overrides": [
13+
{
14+
"parserOptions": {
15+
"project": ["./tsconfig.json", "./tsconfig.spec.json"]
16+
},
17+
"files": [
18+
"src/**/*.ts"
19+
],
20+
"extends": [
21+
"eslint:recommended",
22+
"plugin:@typescript-eslint/recommended",
23+
"plugin:@angular-eslint/recommended",
24+
"plugin:@angular-eslint/template/process-inline-templates",
25+
"plugin:prettier/recommended"
26+
],
27+
"rules": {
28+
"@typescript-eslint/ban-ts-comment": 0,
29+
"no-console": [
30+
"error"
31+
],
32+
"max-lines-per-function": [
33+
1,
34+
{
35+
"max": 40
36+
}
37+
],
38+
"max-lines": [
39+
1,
40+
{
41+
"max": 150
42+
}
43+
],
44+
"@angular-eslint/directive-selector": [
45+
"error",
46+
{
47+
"type": "attribute",
48+
"prefix": "app",
49+
"style": "camelCase"
50+
}
51+
],
52+
"@angular-eslint/component-selector": [
53+
"error",
54+
{
55+
"type": "element",
56+
"prefix": "app",
57+
"style": "kebab-case"
58+
}
59+
],
60+
"simple-import-sort/imports": "error",
61+
"simple-import-sort/exports": "error"
62+
}
63+
}
64+
]
65+
}

.github/workflows/release.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '20'
20+
21+
- name: Setup Corepack
22+
run: |
23+
corepack enable
24+
corepack prepare [email protected] --activate
25+
26+
- name: Install dependencies
27+
run: pnpm install
28+
29+
- name: Build project
30+
run: pnpm run build
31+
32+
- name: Test project
33+
run: pnpm run test:coverage
34+
35+
- name: Release
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
38+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
run: pnpm run release

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
/coverage
9+
10+
# Node
11+
/node_modules
12+
npm-debug.log
13+
yarn-error.log
14+
15+
# IDEs and editors
16+
.idea/
17+
.project
18+
.classpath
19+
.c9/
20+
*.launch
21+
.settings/
22+
*.sublime-workspace
23+
24+
# Visual Studio Code
25+
.vscode/*
26+
!.vscode/settings.json
27+
!.vscode/tasks.json
28+
!.vscode/launch.json
29+
!.vscode/extensions.json
30+
.history/*
31+
32+
# Miscellaneous
33+
/.angular/cache
34+
.sass-cache/
35+
/connect.lock
36+
/coverage
37+
/libpeerconnection.log
38+
testem.log
39+
/typings
40+
.nx/cache
41+
42+
# System files
43+
.DS_Store
44+
Thumbs.db

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.idea/
2+
.github
3+
.gitignore
4+
.prettierrc.json
5+
.DS_Store
6+
CONTRIBUTE.md
7+
8+
# configuration
9+
renovate.json
10+
tsconfig.json
11+
/.vscode
12+
.eslintrc.json
13+
.eslintignore

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"endOfLine": "auto",
5+
"printWidth": 80
6+
}

.releaserc.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @type {import('semantic-release').GlobalConfig}
3+
*/
4+
const releaseConfig = {
5+
branches: ["main"],
6+
"plugins": [
7+
"@semantic-release/commit-analyzer",
8+
"@semantic-release/release-notes-generator",
9+
"@semantic-release/changelog",
10+
"@semantic-release/npm",
11+
"@semantic-release/github",
12+
[
13+
"@semantic-release/git",
14+
{
15+
"assets": ["package.json", "CHANGELOG.md"],
16+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
17+
}
18+
]
19+
]
20+
};
21+
22+
module.exports = releaseConfig;

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# ngx-fastboot
2+
3+
[![Semantic Release](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
4+
[![Build Status](https://img.shields.io/github/actions/workflow/status/KernelPanic92/ngx-fastboot/ci.yml?branch=main)](https://github.com/KernelPanic92/ngx-fastboot/actions)
5+
[![Test Coverage](https://img.shields.io/codecov/c/github/KernelPanic92/ngx-fastboot)](https://codecov.io/gh/KernelPanic92/ngx-fastboot)
6+
[![Angular](https://img.shields.io/badge/angular-%23DD0031.svg?logo=angular&logoColor=white)](https://angular.io/)
7+
[![Tsup](https://img.shields.io/badge/tsup-fast--transpiler-brightgreen)](https://github.com/egoist/tsup)
8+
9+
**ngx-fastboot** is a dynamic configuration loader for Angular applications. It optimizes the startup performance by loading configurations in a separate chunk during compilation.
10+
11+
## Why Use ngx-fastboot?
12+
Modern web applications often require a multitude of providers, which can increase the initial bundle size and slow down application startup. Splitting code into multiple chunks helps mitigate these issues by:
13+
14+
- **Reducing Initial Bundle Size:** By moving configuration-related code into separate chunks, the initial bundle size is minimized, leading to faster load times and improved performance.
15+
- **Improving Load Performance:** Smaller initial bundles load quicker, especially over slower network connections, enhancing the user experience.
16+
- **Mitigating Compilation Warnings:** Angular may generate warnings if the initial bundle size exceeds recommended limits. ngx-fastboot helps distribute the load, reducing the likelihood of these warnings.
17+
18+
## Features
19+
20+
- **Dynamic Configuration Loading**: Load and resolve Angular providers dynamically.
21+
- **Performance Optimization**: Improve application startup performance by offloading configuration to a separate chunk.
22+
- **Seamless Integration**: Easy integration with existing Angular projects.
23+
- **Support for Lazy Configurations**: Load Angular Providers lazily for better performance.
24+
25+
## Installation
26+
27+
with npm:
28+
```bash
29+
npm install ngx-fastboot
30+
```
31+
32+
with pnpm:
33+
```bash
34+
pnpm add ngx-fastboot
35+
```
36+
37+
with yarn:
38+
```bash
39+
yarn add ngx-fastboot
40+
```
41+
42+
## Usage
43+
44+
To use **ngx-fastboot**, import the `fast` function and call it with your Angular application's `bootstrapApplication` function, root component, and configuration options.
45+
46+
### Example
47+
48+
49+
50+
#### Before
51+
52+
```typescript
53+
import { AppComponent } from './app.component';
54+
import { bootstrapApplication } from '@angular/platform-browser';
55+
import provideMyDefaultExportFeatures from './default-export-features.config';
56+
import { provideMyOtherFeatures } from './my-other-features.config';
57+
import { fast } from 'ngx-fastboot';
58+
59+
bootstrapApplication(AppComponent, {
60+
providers: [
61+
MyProvider,
62+
provideMyDefaultExportFeatures,
63+
provideMyOtherFeatures,
64+
]
65+
}).then(appRef => {
66+
console.log('App is bootstrapped');
67+
}).catch(error => {
68+
console.error('Error bootstrapping the app', error);
69+
});
70+
```
71+
72+
#### After
73+
74+
```typescript
75+
import { AppComponent } from './app.component';
76+
import { bootstrapApplication } from '@angular/platform-browser';
77+
import { fast } from 'ngx-fastboot';
78+
79+
fast(bootstrapApplication, AppComponent, {
80+
providers: [
81+
MyProvider,
82+
() => import('./default-export-features.config'), // default export config
83+
() => import('./my-other-features.config').then((m) => m.provideMyOtherFeatures),
84+
]
85+
}).then(appRef => {
86+
console.log('App is bootstrapped');
87+
}).catch(error => {
88+
console.error('Error bootstrapping the app', error);
89+
});
90+
```
91+
92+
## API
93+
94+
### `fast`
95+
96+
Dynamically loads the specified providers in the configuration and bootstraps an Angular application.
97+
98+
#### Parameters
99+
100+
- **`bootstrap`**: The Angular application's bootstrap function (typically `bootstrapApplication`).
101+
- **`rootComponent`**: The root component of the application, which should be of type `Type<unknown>`.
102+
- **`options`**: (Optional) The application configuration, including the providers to be loaded. It should conform to the `FastApplicationConfig` type. Providers can be `Provider`, `EnvironmentProviders`, or lazy modules that return these providers.
103+
104+
#### Returns
105+
106+
A `Promise` that resolves to an `ApplicationRef` instance of the bootstrapped application. The bootstrap method is called with the root component and the updated configuration with the resolved providers.
107+
108+
## Types
109+
110+
### `FastApplicationConfig`
111+
112+
```typescript
113+
export type FastApplicationConfig = ApplicationConfig & {
114+
providers: Array<FastProvider>
115+
}
116+
```
117+
118+
### `FastProvider`
119+
120+
```typescript
121+
export type FastProvider = Provider | EnvironmentProviders | LazyModule<Provider | EnvironmentProviders | Array<Provider | EnvironmentProviders>>;
122+
```
123+
124+
### `LazyModule`
125+
126+
```typescript
127+
export type LazyModule<T> = () => Promise<T | { default: T }>;
128+
```
129+
130+
### `AngularProvider`
131+
132+
```typescript
133+
export type AngularProvider = Provider | EnvironmentProviders;
134+
```
135+
136+
## Contributing
137+
138+
We welcome contributions! Please read our [Contributing Guide](CONTRIBUTING.md) to learn how you can help improve **ngx-fastboot**.
139+
140+
## License
141+
142+
**ngx-fastboot** is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
143+
144+
## Keywords
145+
146+
angular, angular performance, dynamic configuration, lazy loading, angular bootstrap, ngx-fastboot
147+
148+
## Contact
149+
150+
For any questions or feedback, please [open an issue](https://github.com/KernelPanic92/ngx-fastboot/issues).

jest.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
preset: "jest-preset-angular",
3+
setupFilesAfterEnv: [
4+
'<rootDir>/src/setup.jest.ts'
5+
],
6+
testPathIgnorePatterns: [
7+
'<rootDir>/node_modules/',
8+
'<rootDir>/dist/'
9+
],
10+
globals: {
11+
tsConfig: '<rootDir>/tsconfig.spec.json',
12+
},
13+
transform: {
14+
'^.+\\.(ts|js|html)$': 'jest-preset-angular'
15+
}
16+
}

0 commit comments

Comments
 (0)