Created
June 7, 2018 05:12
-
-
Save nevercast/e62157ccf385a9f22d1f68ec04274a5b to your computer and use it in GitHub Desktop.
Babel Polyfill loader for Azure Functions "only one instance of babel-polyfill is allowed"
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
/** | |
* Azure Functions can sometimes share a global scope to save memory (More than one function runs in the same interpreter). | |
* When this occurs, babel will try to load twice. This is bad. | |
* | |
* This file acts as a mediator to prevent it loading twice and always logs the result for my interest. | |
* Inside my webpack.config.js, instead of 'babel-polyfill', I have 'src/polyfill/babel' (this file). | |
*/ | |
if (global._babelPolyfill) { | |
/* Polyfill is already loaded */ | |
if (console && console.warn) { | |
console.warn('Babel Polyfill exits in this shared global scope. I will not load it.') | |
} | |
} else { | |
/* Polyfill is already loaded */ | |
if (console && console.warn) { | |
console.warn('Babel Polyfill is not present in this shared global scope. Loading it.') | |
} | |
require('babel-polyfill') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment