Skip to content

Commit 554e8d9

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

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-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)
15+
}
616

717
export {
818
createStore,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
function isCrushed() {
7+
return true
8+
}
9+
/**
10+
* Function that checks name of isCrushed and NODE_ENV
11+
* to determine if code is minified outside of production
12+
*
13+
* @returns {Boolean} A boolean value that is based on whether or not code
14+
* has been minifed outside side of NODE_ENV === 'production'
15+
*/
16+
export default function isMinifiedOutsideOfProduction() {
17+
return isCrushed.name !== 'isCrushed' && process.env.NODE_ENV !== 'production'
18+
}

0 commit comments

Comments
 (0)