Skip to content

Commit

Permalink
fix(Build): Use browser field in package.json to exclude `cookies…
Browse files Browse the repository at this point in the history
…` library from client build

The `eval` hack from 6c3f044 (#8) would also exclude the `cookies` library
from server builds when using vercel.
Using the `browser` field is way cleaner anyway.

Hopefully fixes #12
  • Loading branch information
bjoluc committed Jan 27, 2021
1 parent 1b4fd55 commit 35edd02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"ts-jest": "26.4.4",
"typescript": "3.9.7"
},
"browser": {
"cookies": false
},
"prettier": {
"trailingComma": "es5",
"tabWidth": 2,
Expand Down
4 changes: 1 addition & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IncomingMessage, ServerResponse } from "http";

import ServerCookies from "cookies";
import { NextComponentType, NextPageContext } from "next";
import {
MakeStore,
Expand All @@ -22,9 +23,6 @@ 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

0 comments on commit 35edd02

Please sign in to comment.