Skip to content
Dashboard

Next.js 5.1: Faster Page Resolution

npm i next@latest react@latest react-dom@latest

In addition to bumping Next.js, we upgrade the peer dependencies `react` and `react-dom`

Link to headingFaster page resolution

Page resolution shown per request. Left is Next.js 5.0, right is Next.js 5.1
Page resolution shown per request. Left is Next.js 5.0, right is Next.js 5.1

Link to headingEnvironment configuration

next.config.js
module.exports = {
serverRuntimeConfig: { // Will only be available on the server side
mySecret: 'secret'
},
publicRuntimeConfig: { // Will be available on both server and client
staticFolder: '/static'
}
}

Both `serverRuntimeConfig` and `publicRuntimeConfig` are defined in `next.config.js`

pages/index.js
import getConfig from 'next/config'
const {serverRuntimeConfig, publicRuntimeConfig} = getConfig()
console.log(serverRuntimeConfig.mySecret) // Will only be available on the server side
console.log(publicRuntimeConfig.staticFolder) // Will be available on both server and client
export default () => <div>
<img src='\${publicRuntimeConfig.staticFolder}/logo.png' />
</div>

The `getConfig` method from the `next/config` module is used to get configuration values

Link to headingImproved Error Handling

Link to headingPhases / config function

module.exports = (phase, {defaultConfig}) => config

`next.config.js` exporting a function that returns the user configuration

const {PHASE_DEVELOPMENT_SERVER} = require('next/constants')
module.exports = (phase, {defaultConfig}){
if(phase === PHASE_DEVELOPMENT_SERVER) {
return { /* development only config options here */ }
}
return { /* config options for all phases except development here */ }
}

`next.config.js` that checks for the development phase

Link to headingImproved production source map generation

module.exports = {
webpack(config, {dev}) {
if (!dev) {
config.devtool = 'source-map';
for (const plugin of config.plugins) {
if (plugin['constructor']['name'] === 'UglifyJsPlugin') {
plugin.options.sourceMap = true;
break;
}
}
}
return config
}
}

Manually enable source maps in `next.config.js`

const withSourceMaps = require('@zeit/next-source-maps')
module.exports = withSourceMaps()

Using `@zeit/next-source-maps` to enable source maps in `next.config.js`

The source code is shown in the sources panel
The source code is shown in the sources panel

Link to headingNew plugins / improvements to existing ones

Link to headingThank you