Skip to content

Commit 26226bf

Browse files
Merge pull request cerebral#294 from FWeinb/reduce-prod-build
Reduce production bundle size by 1/3
2 parents e442819 + b2e9ac7 commit 26226bf

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ import {
3838
MockedEventEmitter,
3939
makeStringifySafeMutations,
4040
mergeState,
41-
IS_DEVELOPMENT,
4241
IS_TEST,
43-
IS_PRODUCTION,
4442
IS_OPERATOR,
4543
getFunctionName,
4644
getActionPaths,
@@ -211,7 +209,7 @@ export class Overmind<ThisConfig extends IConfiguration>
211209
const name = options.name || 'OvermindApp'
212210

213211
if (
214-
IS_DEVELOPMENT &&
212+
(!process.env.NODE_ENV || process.env.NODE_ENV === 'development') &&
215213
mode.mode === MODE_DEFAULT &&
216214
options.hotReloading !== false &&
217215
!(process && process.title && process.title.includes('node'))
@@ -238,7 +236,7 @@ export class Overmind<ThisConfig extends IConfiguration>
238236
const proxyStateTree = this.createProxyStateTree(
239237
configuration,
240238
eventHub,
241-
mode.mode === MODE_SSR ? false : IS_DEVELOPMENT
239+
mode.mode === MODE_SSR ? false : process.env.NODE_ENV === 'development'
242240
)
243241

244242
this.originalConfiguration = configuration
@@ -253,7 +251,7 @@ export class Overmind<ThisConfig extends IConfiguration>
253251
}
254252

255253
if (
256-
IS_DEVELOPMENT &&
254+
process.env.NODE_ENV === 'development' &&
257255
mode.mode === MODE_DEFAULT &&
258256
typeof window !== 'undefined'
259257
) {
@@ -302,7 +300,7 @@ export class Overmind<ThisConfig extends IConfiguration>
302300
}
303301
}
304302

305-
if (IS_PRODUCTION && mode.mode === MODE_DEFAULT) {
303+
if (process.env.NODE_ENV === 'production' && mode.mode === MODE_DEFAULT) {
306304
eventHub.on(EventType.OPERATOR_ASYNC, () => {
307305
proxyStateTree.getMutationTree().flush(true)
308306
})
@@ -389,7 +387,7 @@ export class Overmind<ThisConfig extends IConfiguration>
389387
return proxyStateTree
390388
}
391389
private createExecution(name, action, parentExecution) {
392-
if (IS_PRODUCTION) {
390+
if (process.env.NODE_ENV === 'production') {
393391
return ({
394392
[EXECUTION]: true,
395393
parentExecution,
@@ -483,7 +481,7 @@ export class Overmind<ThisConfig extends IConfiguration>
483481
boundExecution =
484482
boundExecution && boundExecution[EXECUTION] ? boundExecution : undefined
485483

486-
if (IS_PRODUCTION || action[IS_OPERATOR]) {
484+
if (process.env.NODE_ENV === 'production' || action[IS_OPERATOR]) {
487485
const execution = this.createExecution(name, action, boundExecution)
488486
this.eventHub.emit(EventType.ACTION_START, {
489487
...execution,
@@ -622,7 +620,7 @@ export class Overmind<ThisConfig extends IConfiguration>
622620
return actionFunc
623621
}
624622
private trackEffects(effects = {}, execution) {
625-
if (IS_PRODUCTION) {
623+
if (process.env.NODE_ENV === 'production') {
626624
return effects
627625
}
628626

@@ -799,7 +797,7 @@ export class Overmind<ThisConfig extends IConfiguration>
799797
} else if (typeof value === 'function') {
800798
aggr[key] = new Derived(value)
801799

802-
if (IS_DEVELOPMENT) {
800+
if (process.env.NODE_ENV === 'development') {
803801
this.derivedReferences.push(aggr[key])
804802
}
805803
} else {

packages/node_modules/overmind/src/operator.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
IS_PRODUCTION,
32
IS_OPERATOR,
43
makeStringifySafeMutations,
54
createActionsProxy,
@@ -10,7 +9,7 @@ import { safeValue } from './Devtools'
109
import { IContext, IConfiguration, IOperator } from './types'
1110

1211
export function operatorStarted(type, arg, context) {
13-
if (IS_PRODUCTION) {
12+
if (process.env.NODE_ENV === 'production') {
1413
return
1514
}
1615
const name =
@@ -32,7 +31,7 @@ export function operatorStopped(
3231
isSkipped?: boolean
3332
} = {}
3433
) {
35-
if (IS_PRODUCTION) {
34+
if (process.env.NODE_ENV === 'production') {
3635
if (value instanceof Promise) {
3736
context.execution.emit(EventType.OPERATOR_ASYNC, {
3837
...context.execution,
@@ -74,7 +73,7 @@ export function operatorStopped(
7473
}
7574

7675
export function createContext(context, value, path?) {
77-
if (IS_PRODUCTION) {
76+
if (process.env.NODE_ENV === 'production') {
7877
return {
7978
...context,
8079
value,
@@ -103,7 +102,7 @@ export function createContext(context, value, path?) {
103102
}
104103

105104
export function createNextPath(next) {
106-
if (IS_PRODUCTION) {
105+
if (process.env.NODE_ENV === 'production') {
107106
return next
108107
}
109108

@@ -235,7 +234,7 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
235234
const operator = (err, context, next, final) => {
236235
operatorStarted(type, name, context)
237236
const mutationTree = context.execution.getMutationTree()
238-
if (!IS_PRODUCTION) {
237+
if (!(process.env.NODE_ENV === 'production')) {
239238
mutationTree.onMutation((mutation) => {
240239
context.execution.emit(EventType.MUTATIONS, {
241240
...context.execution,
@@ -252,7 +251,7 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
252251
effects: context.effects,
253252
actions: context.actions,
254253
},
255-
IS_PRODUCTION
254+
process.env.NODE_ENV === 'production'
256255
? context.value
257256
: context.execution.scopeValue(context.value, mutationTree),
258257
(err, value, options = {}) => {
@@ -283,7 +282,7 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
283282
}
284283
)
285284

286-
if (!IS_PRODUCTION) {
285+
if (!(process.env.NODE_ENV === 'production')) {
287286
let pendingFlush
288287
mutationTree.onMutation(() => {
289288
if (pendingFlush) {

packages/node_modules/overmind/src/utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { IMutation } from 'proxy-state-tree'
33
import { safeValues } from './Devtools'
44

55
export const IS_TEST = process.env.NODE_ENV === 'test'
6-
export const IS_PRODUCTION = process.env.NODE_ENV === 'production'
7-
export const IS_DEVELOPMENT =
8-
!process.env.NODE_ENV || process.env.NODE_ENV === 'development'
96
export const IS_OPERATOR = Symbol('operator')
107
export const ORIGINAL_ACTIONS = Symbol('origina_actions')
118
export const EXECUTION = Symbol('execution')

0 commit comments

Comments
 (0)