Created
April 22, 2019 05:19
-
-
Save junibrosas/70d47fdadc302ae0df39f54ddfe956a2 to your computer and use it in GitHub Desktop.
Next.js with polyfills
This file contains 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
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 | |
} | |
} |
This file contains 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
/* 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