Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
remove dev logs from production build
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Dec 13, 2020
1 parent e0e6de5 commit 588c57c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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'],
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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\`!`);
}
Expand Down Expand Up @@ -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\``
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 0 additions & 1 deletion src/utils/isDev.ts

This file was deleted.

2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 588c57c

Please sign in to comment.