Skip to content

Commit

Permalink
fix(Build): Exclude server-side cookies library from Webpack build
Browse files Browse the repository at this point in the history
The client build of a Next.js project with next-redux-cookie-wrapper would previously include the
server-only library `cookies` and the dependencies thereof. Thanks @Pikachews!

Fixes #8
  • Loading branch information
bjoluc committed Jul 18, 2020
1 parent d9e0315 commit 6c3f044
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { IncomingMessage, ServerResponse } from "http";

import ServerCookies from "cookies";
import ClientCookies from "cookies-js";
import { NextComponentType, NextPageContext } from "next";
import {
MakeStore,
Expand All @@ -24,6 +22,9 @@ import {
// @ts-ignore No type definitions and we do not want to create a global definition in this package
import { CookieStorage, NodeCookiesWrapper } from "redux-persist-cookie-storage";

// Import `cookies` only on server side
const ServerCookies = typeof window === "undefined" ? eval('require("cookies")') : null;

export type CustomPersistConfig<S> = Omit<PersistConfig<S>, "storage" | "key"> &
Partial<Pick<PersistConfig<S>, "key">>;

Expand Down Expand Up @@ -162,7 +163,7 @@ export const withReduxCookiePersist = (makeStore: MakeStore, config?: Config) =>
// Let's persist the store!
const persistConfig = {
...sharedPersistConfig,
storage: new CookieStorage(ClientCookies, sharedCookieConfig),
storage: new CookieStorage(require("cookies-js"), sharedCookieConfig),
};

// Note: We do not create a persistor here because we need no rehydration.
Expand Down

0 comments on commit 6c3f044

Please sign in to comment.