From 35edd022cf56153798badc0693d77b68495aba46 Mon Sep 17 00:00:00 2001 From: bjoluc Date: Wed, 27 Jan 2021 18:58:59 +0100 Subject: [PATCH] fix(Build): Use `browser` field in `package.json` to exclude `cookies` 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 --- package.json | 3 +++ src/index.tsx | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f774f7a..18d6f20 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,9 @@ "ts-jest": "26.4.4", "typescript": "3.9.7" }, + "browser": { + "cookies": false + }, "prettier": { "trailingComma": "es5", "tabWidth": 2, diff --git a/src/index.tsx b/src/index.tsx index 1b379a2..de622c9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,6 @@ import { IncomingMessage, ServerResponse } from "http"; +import ServerCookies from "cookies"; import { NextComponentType, NextPageContext } from "next"; import { MakeStore, @@ -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 = Omit, "storage" | "key"> & Partial, "key">>;