Skip to content

Commit 56592f7

Browse files
committed
warn user when using minified code outside of NODE_ENV 'production'
1 parent 9c35fd6 commit 56592f7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import combineReducers from './utils/combineReducers'
33
import bindActionCreators from './utils/bindActionCreators'
44
import applyMiddleware from './utils/applyMiddleware'
55
import compose from './utils/compose'
6+
import isMinifiedOutsideOfProduction from './utils/isMinifiedOutsideOfProduction'
7+
8+
if (isMinifiedOutsideOfProduction()) {
9+
var warningMessage = 'You are utilzing minified code outside of NODE_ENV === \'production\'. ' +
10+
'This means that you are running a slower development only build of Redux. ' +
11+
'Consult tools such as loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
12+
'and DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
13+
'to build with proper NODE_ENV'
14+
console.error(warningMessage) // eslint-disable-line no-console
15+
}
616

717
export {
818
createStore,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* This is a function that exists for the function isMinifiedOutsideOfProduction to perform a check.
3+
* If this function does not maintain its name and the NODE_ENV is not === 'production'
4+
* then we know the user is using minified code outside of production and we should warn
5+
*
6+
* @returns {Boolean} returns true, is a function that just exists for purpose of checking minifcation
7+
*/
8+
function isCrushed() {
9+
return true
10+
}
11+
/**
12+
* Function that checks name of isCrushed and NODE_ENV
13+
* to determine if code is minified outside of production
14+
*
15+
* @returns {Boolean} A boolean value that is based on whether or not code
16+
* has been minifed outside side of NODE_ENV === 'production'
17+
*/
18+
export default function isMinifiedOutsideOfProduction() {
19+
return isCrushed.name !== 'isCrushed' && process.env.NODE_ENV !== 'production'
20+
}

0 commit comments

Comments
 (0)