Skip to content

Instantly share code, notes, and snippets.

@nevercast
Created June 7, 2018 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nevercast/e62157ccf385a9f22d1f68ec04274a5b to your computer and use it in GitHub Desktop.
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"
/**
* 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