Created
December 14, 2017 08:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.' | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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