diff --git a/package.json b/package.json index 1b670092..e11d6512 100644 --- a/package.json +++ b/package.json @@ -122,6 +122,7 @@ "@babel/plugin-transform-runtime": "^7.12.10", "@reduxjs/toolkit": "^1.5.0", "@rollup/plugin-babel": "^5.2.2", + "@rollup/plugin-replace": "^2.3.4", "@rollup/plugin-typescript": "^8.0.0", "@size-limit/preset-small-lib": "^4.6.0", "@testing-library/react": "^11.1.0", diff --git a/rollup.config.js b/rollup.config.js index 3695ef7f..0ba66d15 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,6 +1,7 @@ import babel from '@rollup/plugin-babel'; import typescript from '@rollup/plugin-typescript'; import { terser } from 'rollup-plugin-terser'; +import replace from '@rollup/plugin-replace'; /** @type {import("rollup").RollupOptions} */ const defaultConfig = { @@ -74,6 +75,11 @@ const configs = [ ? defaultTsConfig : { ...defaultTsConfig, declarationDir: 'dist/ts', declaration: true, declarationMap: true } ), + replace({ + values: { + 'process.env.NODE_ENV': JSON.stringify(minfied ? 'production' : 'development'), + }, + }), babel({ exclude: 'node_modules/**', extensions: ['.js', '.ts'], diff --git a/src/index.ts b/src/index.ts index ae30a454..3eb756b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ import { isQueryDefinition, } from './endpointDefinitions'; import { assertCast } from './tsHelpers'; -import { capitalize, IS_DEV } from './utils'; +import { capitalize } from './utils'; import { onFocus, onFocusLost, onOnline, onOffline } from './setupListeners'; export { ApiProvider } from './ApiProvider'; export { QueryStatus } from './apiState'; @@ -62,7 +62,7 @@ export function createApi< const endpointDefinitions: EndpointDefinitions = {}; const assertEntityType: AssertEntityTypes = (entity) => { - if (IS_DEV()) { + if (typeof process !== 'undefined' && process.env.NODE_ENV === 'development') { if (!entityTypes.includes(entity.type as any)) { console.error(`Entity type '${entity.type}' was used, but not specified in \`entityTypes\`!`); } @@ -163,7 +163,7 @@ export function createApi< mutation: (x) => ({ ...x, type: DefinitionType.mutation } as any), }); for (const [endpoint, definition] of Object.entries(evaluatedEndpoints)) { - if (IS_DEV()) { + if (typeof process !== 'undefined' && process.env.NODE_ENV === 'development') { if (!inject.overrideExisting && endpoint in endpointDefinitions) { console.error( `called \`injectEndpoints\` to override already-existing endpoint ${endpoint} without specifying \`overrideExisting: true\`` diff --git a/src/utils/index.ts b/src/utils/index.ts index f919c39e..2580c354 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,6 +5,5 @@ export * from './flatten'; export * from './shallowEqual'; export * from './useShallowStableValue'; export * from './capitalize'; -export * from './isDev'; export * from './isOnline'; export * from './isDocumentVisible'; diff --git a/src/utils/isDev.ts b/src/utils/isDev.ts deleted file mode 100644 index 16e49bb8..00000000 --- a/src/utils/isDev.ts +++ /dev/null @@ -1 +0,0 @@ -export const IS_DEV = () => typeof process !== 'undefined' && process.env.NODE_ENV === 'development'; diff --git a/yarn.lock b/yarn.lock index 06da2e54..30723546 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1222,7 +1222,7 @@ is-module "^1.0.0" resolve "^1.17.0" -"@rollup/plugin-replace@^2.2.1": +"@rollup/plugin-replace@^2.2.1", "@rollup/plugin-replace@^2.3.4": version "2.3.4" resolved "https://registry.yarnpkg.com/@rollup/plugin-replace/-/plugin-replace-2.3.4.tgz#7dd84c17755d62b509577f2db37eb524d7ca88ca" integrity sha512-waBhMzyAtjCL1GwZes2jaE9MjuQ/DQF2BatH3fRivUF3z0JBFrU0U6iBNC/4WR+2rLKhaAhPWDNPYp4mI6RqdQ==