Unverified Commit 92637a9b authored by Lee Robinson's avatar Lee Robinson Committed by GitHub

Update with-polyfills example. (#20996)

From https://github.com/vercel/next.js/discussions/20992.
parent f9b7a391
# Example app with polyfills # With Polyfills
> ❗️ Warning: This example is not the suggested way to add polyfills and is known to cause issues with bundling. See [the browser support docs](https://nextjs.org/docs/basic-features/supported-browsers-features#custom-polyfills) for the correct way to load polyfills. Next.js supports IE11 and all modern browsers (Edge, Firefox, Chrome, Safari, Opera, et al) with no required configuration. It also adds [some polyfills](https://nextjs.org/docs/basic-features/supported-browsers-features#polyfills) by default.
Next.js supports modern browsers and IE 11. It loads required polyfills automatically. If you need to add custom polyfills, you can follow this example. If your own code or any external npm dependencies require features not supported by your target browsers, you need to add polyfills yourself.
In this case, you should add a top-level import for the specific polyfill you need in your Custom `<App>` or the individual component.
## Deploy your own ## Deploy your own
......
/* eslint no-extend-native: 0 */
// This file runs before React and Next.js core
// This file is loaded for all browsers
// Next.js includes a number of polyfills only for older browsers like IE11
// Make sure you don't duplicate these in this file
// https://github.com/vercel/next.js/blob/canary/packages/next-polyfill-nomodule/src/index.js
console.log('Load your 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
},
}
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^16.7.0", "react": "latest",
"react-dom": "^16.7.0" "react-dom": "latest"
}, },
"license": "MIT" "license": "MIT"
} }
// Add your polyfills here or at the component level.
// For example...
// import 'resize-observer-polyfill'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
console.log('Inside the /index.js page')
export default function Home() { export default function Home() {
return <div>Hello World</div> return <div>Hello World</div>
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment