-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to exclude withDevTools in production mode when ngrx-toolkit is installed under dependencies #53
Comments
Is there any possibility to exclude withDevtools in production mode... |
Hi there, I have a solution for this although it is a bit hacky: environment.ts: import { withDevtools } from '@angular-architects/ngrx-toolkit';
export const environment = {
storeDevToolsFeature: withDevtools
} environment.prod.ts export const environment = {
storeDevToolsFeature: ((_: string) => store => store) as (name: string) => SignalStoreFeature
} If you have a type defined for your environment, you can use the type and skip above type assertion: {
storeDevToolsFeature: (name: string) => SignalStoreFeature
} Then all you need to do is replace export const SomeStore = signalStore(
withState({strings: [] as string[] }),
environment.storeDevToolsFeature('some')
); Make sure you have file replacements in angular.json prod configuration: "fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
] As a result, when running the prod version of ng serve or build this file will be replaced and not compiled at all, which will disable and tree-shake the whole withDevTools feature 😀 |
We could use
@marcindz88 would you have time to implement that and provide a PR? |
@rainerhahnekamp I thought about adding isDevMode but this leads to the withDevTools code to be included in the production bundle, unless there is some method to mark it for exclusion that I don't know. |
Hmm, I may be wrong about that, I will check if it is tree shaken by default and if yes, I will provide a PR |
i have tried as you post @marcindz88 but i got the below error while importing environment file of production |
i have tried withdevtools @rainerhahnekamp it will not works for me |
@rainerhahnekamp Hmm, I have this (and more) in my prod bundle when using isDevMode: function fo() {
$(() => {
if (!Vt) return;
let t = Oe(),
e = {};
for (let i in t) {
let s = t[i];
e[i] = s();
}
let o = Array.from(ie),
n = o.length ? o.join(', ') : 'Store Update';
(ie = new Set()), Vt.send({ type: n }, e);
});
}
function mo(t, e) {
if (typeof t == 'object' && t && e in t) return t[e];
}
function ho(t) {
let [e] = Object.getOwnPropertySymbols(t);
if (!e) throw new Error('Cannot find State Signal');
return mo(t, e);
}
var Vt;
function Ue(t) {
return e => {
if (Bt(E(nt))) return e;
let n = window.__REDUX_DEVTOOLS_EXTENSION__;
if (!n) return e;
Vt || (Vt = n.connect({ name: 'NgRx Signal Store' }));
let i = ho(e);
return Oe.update(s => g(r({}, s), { [t]: i })), je || (fo(), (je = !0)), e;
};
} |
@REVenkatesan if you don't type your environment which I would encourage you to do, to reduce the probability of having different Environment types, you probably need to add a type assertion as |
@REVenkatesan we will find a solution for the typing issue you reported. Once @marcindz88 says it is tree shaken, it will be added to the next release. |
@rainerhahnekamp I think this is related to this issue: angular/angular#51175. |
@marcindz88, I see two use cases for this feature:
I'd say |
@koempf has just been merged. it is part of the docs. |
No description provided.
The text was updated successfully, but these errors were encountered: