Skip to content

Commit 4c2baa9

Browse files
marcindz88rainerhahnekamp
authored andcommitted
feat: withDevTools disabled in prod, and tree-shaking docs
1 parent 4c38b99 commit 4c2baa9

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,52 @@ patchState(this.store, { loading: false });
8888
updateState(this.store, 'update loading', { loading: false });
8989
```
9090

91+
`withDevtools()` is by default enabled in production mode, if you want to tree-shake it from the application bundle you need to abstract it in your environment file.
92+
93+
<details>
94+
95+
<summary>Devtools tree-shaking details</summary>
96+
97+
environment.ts:
98+
```typescript
99+
import { withDevtools } from '@angular-architects/ngrx-toolkit';
100+
101+
export const environment = {
102+
storeWithDevTools: withDevtools
103+
}
104+
```
105+
106+
environment.prod.ts
107+
```typescript
108+
import { withDevtoolsStub } from '@angular-architects/ngrx-toolkit';
109+
110+
export const environment = {
111+
storeWithDevTools: withDevToolsStub
112+
}
113+
```
114+
115+
Then all you need to do is replace `withDevTools` everywhere in your app with `environment.storeWithDevTools`
116+
e.g.:
117+
```typescript
118+
export const SomeStore = signalStore(
119+
withState({strings: [] as string[] }),
120+
environment.storeWithDevTools('featureName')
121+
);
122+
```
123+
124+
Also make sure you have defined file replacements in angular.json prod configuration:
125+
```json
126+
"fileReplacements": [
127+
{
128+
"replace": "src/environments/environment.ts",
129+
"with": "src/environments/environment.prod.ts"
130+
}
131+
]
132+
```
133+
134+
</details>
135+
136+
91137
## Redux: `withRedux()`
92138

93139
`withRedux()` bring back the Redux pattern into the Signal Store.

libs/ngrx-toolkit/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {
2+
withDevToolsStub,
23
withDevtools,
34
patchState,
45
updateState,

libs/ngrx-toolkit/src/lib/with-devtools.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export function reset() {
7979
storeRegistry.set({});
8080
}
8181

82+
/**
83+
* Stub for DevTools integration. Can be used to disable DevTools in production.
84+
*/
85+
export const withDevToolsStub: typeof withDevtools = () => store => store;
86+
8287
/**
8388
* @param name store's name as it should appear in the DevTools
8489
*/

0 commit comments

Comments
 (0)