Skip to content
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

[Store-DevTools] Documentation: Example on excluding store-devtools in production build #1521

Closed
MattiJarvinen opened this issue Jan 23, 2019 · 6 comments · Fixed by #2073
Closed
Assignees
Labels
Accepting PRs community watch Someone from the community is working this issue/PR Comp: Docs Project: Store Devtools

Comments

@MattiJarvinen
Copy link

I followed examples in old repository issues to remove store-devtools from production build. When inspecting stats.json with webpack-bundle-inspector I noticed that it was still compiled in the main bundle.

ngrx.io or store-devtools README could include instructions on how to exclude module import in production. It's quite trivial and more related to angular itself but it's not obvious before you've seen it. Just google "typescript conditional import" and you get bucket full of confusion.

Add to angular.json under your production build.

"fileReplacements": [
    {
        "replace": "src/environments/environment.ts",
        "with": "src/environments/environment.prod.ts"
    },
    {
        "replace": "src/app/build-specifics/index.ts",
        "with": "src/app/build-specifics/index.prod.ts"
    }
]

Where build-specifics/index.prod.ts is:

export const extModules = [];
export const extMetaReducers = [];

Where build-specifics/index.ts is:

import { ActionReducer } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { storeFreeze } from 'ngrx-store-freeze';
import { environment } from '../../environments/environment';

export const extModules = [
    StoreDevtoolsModule.instrument({
        maxAge: 25
    })
];
export const extMetaReducers = [
    storeFreeze
];

On app.module.ts

import { extMetaReducers, extModules } from './build-specifics';

export const metaReducers: MetaReducer<any>[] = [
    ...extMetaReducers
];

const modules = [
    StoreModule.forRoot(reducers, { metaReducers }),
    HttpClientModule,
    RouterModule,
    //
   ...extModules
];

@NgModule( {
    bootstrap: [AppComponent],
    declarations: [
        ...widgets,
        ...pages
    ],
    imports: [
        ...modules,
        routing
    ],
    providers: [
        ...services
    ]
})
// and so on

Other information:

Related wrong answer in old repository ngrx/store-devtools#53 (comment)

I would be willing to submit a PR for the docs ❤️

[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@brandonroberts
Copy link
Member

This seems reasonable to me a recipe for Store Devtools

@brandonroberts brandonroberts added Project: Store Devtools community watch Someone from the community is working this issue/PR labels Feb 18, 2019
@MattiJarvinen
Copy link
Author

I'll try to get this done within 2 weeks.

@yorraksahb
Copy link

How can we do it using custom webpack configuration and not using angular-cli.

@EnricoVogt
Copy link
Contributor

@yorraksahb i would try it with the CopyWebpackPlugin
https://webpack.js.org/plugins/copy-webpack-plugin/

@Spawnrad
Copy link

Thank you

@sod
Copy link

sod commented Sep 5, 2019

@yorraksahb you can also use hostReplacementPaths option of the AngularCompilerPlugin.

jordanpowell88 added a commit to jordanpowell88/platform that referenced this issue Nov 8, 2019
ActionType is useful for extracting the response type of the new action creators.

feat(store): add verbose error message for undefined feature state in development mode (ngrx#2078)

Closes ngrx#1897

docs(store-devtools): add recipe to exclude store-devtools from the build (ngrx#2073)

Closes ngrx#1521

fix(store): add DefaultProjectorFn to public API (ngrx#2090)

Allows you to fully type the selector without reaching into the src folder

ci: fix filters on tags for publishing to npm and deployment of docs (ngrx#2091)

* refactor(data): use createEffect function instead of @effect decorator
jordanpowell88 pushed a commit to jordanpowell88/platform that referenced this issue Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepting PRs community watch Someone from the community is working this issue/PR Comp: Docs Project: Store Devtools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants