2018-12-07 10:40:06 +03:00
|
|
|
/* eslint-disable no-console */
|
2018-12-07 10:54:44 +03:00
|
|
|
const sync = require('./sync')
|
2018-12-07 11:42:14 +03:00
|
|
|
const {CI, NODE_ENV, NOW_URL} = process.env
|
2018-12-07 10:54:44 +03:00
|
|
|
|
2018-12-08 01:21:39 +03:00
|
|
|
module.exports = (nextConfig = {}) => {
|
|
|
|
const {assetPrefix = NOW_URL || ''} = nextConfig
|
2018-12-07 10:54:44 +03:00
|
|
|
|
|
|
|
let configured = false
|
2018-12-04 02:54:04 +03:00
|
|
|
|
|
|
|
return Object.assign({}, nextConfig, {
|
2018-12-08 01:21:39 +03:00
|
|
|
assetPrefix,
|
|
|
|
pageExtensions: ['js', 'jsx', 'md', 'mdx'],
|
|
|
|
|
|
|
|
publicRuntimeConfig: Object.assign({
|
|
|
|
assetPrefix,
|
|
|
|
production: NODE_ENV === 'production'
|
|
|
|
}, nextConfig.publicRuntimeConfig),
|
|
|
|
|
2018-12-04 02:54:04 +03:00
|
|
|
webpack(config, options) {
|
|
|
|
if (!options.defaultLoaders) {
|
|
|
|
throw new Error(
|
|
|
|
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-01-17 03:30:59 +03:00
|
|
|
const {dev, isServer} = options
|
2018-12-07 10:54:44 +03:00
|
|
|
|
2018-12-07 11:42:14 +03:00
|
|
|
// only attempt to sync locally and in CI
|
2018-12-08 01:21:39 +03:00
|
|
|
if (dev && !configured) {
|
|
|
|
sync({watch: !CI})
|
2018-12-07 10:54:44 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:37:31 +03:00
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.svg$/,
|
2018-12-05 11:59:45 +03:00
|
|
|
use: '@svgr/webpack'
|
2018-12-05 00:37:31 +03:00
|
|
|
})
|
|
|
|
|
2018-12-04 02:54:04 +03:00
|
|
|
config.module.rules.push({
|
2018-12-08 01:21:39 +03:00
|
|
|
test: /\.mdx?$/,
|
2018-12-08 03:08:48 +03:00
|
|
|
use: [
|
|
|
|
options.defaultLoaders.babel,
|
2018-12-14 08:38:25 +03:00
|
|
|
require.resolve('./mdx-loader')
|
2018-12-08 03:08:48 +03:00
|
|
|
]
|
2018-12-04 02:54:04 +03:00
|
|
|
})
|
|
|
|
|
2018-12-07 10:54:44 +03:00
|
|
|
configured = true
|
2018-12-04 02:54:04 +03:00
|
|
|
if (typeof nextConfig.webpack === 'function') {
|
|
|
|
return nextConfig.webpack(config, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|