Skip to content

Instantly share code, notes, and snippets.

@junibrosas
Created April 22, 2019 05:19
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 junibrosas/70d47fdadc302ae0df39f54ddfe956a2 to your computer and use it in GitHub Desktop.
Save junibrosas/70d47fdadc302ae0df39f54ddfe956a2 to your computer and use it in GitHub Desktop.
Next.js with polyfills
module.exports = {
webpack: function (cfg) {
const originalEntry = cfg.entry
cfg.entry = async () => {
const entries = await originalEntry()
if (
entries['main.js'] &&
!entries['main.js'].includes('./client/polyfills.js')
) {
entries['main.js'].unshift('./client/polyfills.js')
}
return entries
}
return cfg
}
}
/* eslint no-extend-native: 0 */
// core-js comes with Next.js. So, you can import it like below
import includes from 'core-js/library/fn/string/virtual/includes'
import repeat from 'core-js/library/fn/string/virtual/repeat'
import assign from 'core-js/library/fn/object/assign'
// Add your polyfills
// This files runs at the very beginning (even before React and Next.js core)
console.log('Load your polyfills')
String.prototype.includes = includes
String.prototype.repeat = repeat
Object.assign = assign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment