Skip to content

Commit

Permalink
warn user when using minified code outside of NODE_ENV 'production'
Browse files Browse the repository at this point in the history
  • Loading branch information
conorhastings committed Nov 26, 2015
1 parent 9c35fd6 commit 56592f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import combineReducers from './utils/combineReducers'
import bindActionCreators from './utils/bindActionCreators'
import applyMiddleware from './utils/applyMiddleware'
import compose from './utils/compose'
import isMinifiedOutsideOfProduction from './utils/isMinifiedOutsideOfProduction'

if (isMinifiedOutsideOfProduction()) {
var warningMessage = 'You are utilzing minified code outside of NODE_ENV === \'production\'. ' +
'This means that you are running a slower development only build of Redux. ' +
'Consult tools such as loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
'and DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
'to build with proper NODE_ENV'
console.error(warningMessage) // eslint-disable-line no-console
}

export {
createStore,
Expand Down
20 changes: 20 additions & 0 deletions src/utils/isMinifiedOutsideOfProduction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* This is a function that exists for the function isMinifiedOutsideOfProduction to perform a check.
* If this function does not maintain its name and the NODE_ENV is not === 'production'
* then we know the user is using minified code outside of production and we should warn
*
* @returns {Boolean} returns true, is a function that just exists for purpose of checking minifcation
*/
function isCrushed() {
return true
}
/**
* Function that checks name of isCrushed and NODE_ENV
* to determine if code is minified outside of production
*
* @returns {Boolean} A boolean value that is based on whether or not code
* has been minifed outside side of NODE_ENV === 'production'
*/
export default function isMinifiedOutsideOfProduction() {
return isCrushed.name !== 'isCrushed' && process.env.NODE_ENV !== 'production'
}

0 comments on commit 56592f7

Please sign in to comment.