Skip to content

Instantly share code, notes, and snippets.

@NikaBuligini
Created December 14, 2017 08:31
Show Gist options
  • Select an option

  • Save NikaBuligini/3e2875b0700d31952b98cfd5442d1955 to your computer and use it in GitHub Desktop.

Select an option

Save NikaBuligini/3e2875b0700d31952b98cfd5442d1955 to your computer and use it in GitHub Desktop.
This piece of code checks if function name has been altered by minification and env is not production
import warning from 'warning';
/*
* This is a dummy function to check if the function name has been altered by minification.
* If the function has been minified and NODE_ENV !== 'production', warn the user.
*/
function isCrushed() {}
if (
process.env.NODE_ENV !== 'production' &&
typeof isCrushed.name === 'string' &&
isCrushed.name !== 'isCrushed'
) {
warning(
"You are currently using minified code outside of NODE_ENV === 'production'. " +
'This means that you are running a slower development build.'
)
}
/**
* Prints a warning in the console if it exists.
*
* @param {String} message The warning message.
* @returns {void}
*/
export default function warning(message) {
/* eslint-disable no-console */
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message)
}
/* eslint-enable no-console */
try {
// This error was thrown as a convenience so that if you enable
// "break on all exceptions" in your console,
// it would pause the execution at this line.
throw new Error(message)
} catch (e) {} // eslint-disable-line no-empty
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment