1
1
mirror of https://github.com/primer/css.git synced 2024-11-30 11:17:05 +03:00
css/lib/config.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-console */
const sync = require('./sync')
2018-12-07 11:42:14 +03:00
const {CI, NODE_ENV, NOW_URL} = process.env
2018-12-08 01:21:39 +03:00
module.exports = (nextConfig = {}) => {
const {assetPrefix = NOW_URL || ''} = nextConfig
let configured = false
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),
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'
)
}
const {dev, isServer} = options
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-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
})
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,
require.resolve('./mdx-loader')
2018-12-08 03:08:48 +03:00
]
})
configured = true
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
}
})
}