This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
68 lines (57 loc) · 1.77 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const path = require('path')
const webpack = require('webpack')
const glob = require('glob')
const withPlugins = require('next-compose-plugins')
const withCSS = require('@zeit/next-css')
const withSourceMaps = require('@zeit/next-source-maps')
const optimizedImages = require('next-optimized-images')
const withOffline = require('next-offline')
const webpackExtra = require('./webpack.extra')
require('dotenv').config()
const nextConfiguration = {
webpack: (nextConfig, options) => {
const entryFactory = nextConfig.entry
const { isServer, defaultLoaders } = options
const config = { ...nextConfig, ...webpackExtra }
config.plugins = [...config.plugins, new webpack.EnvironmentPlugin(process.env)]
config.module.rules.push({
test: /\.+(js|jsx)$/,
include: [path.resolve(process.cwd(), 'components')],
use: [defaultLoaders.babel],
})
if (!isServer) {
return {
...config,
entry: () =>
entryFactory().then(entry => {
const main = entry['main.js']
const pages = glob.sync('./src/pages/**/*.js').map(page => page.replace('src/', ''))
return {
...entry,
'main.js': [...main, ...pages],
}
}),
}
}
return config
},
poweredByHeader: false,
rootPaths: ['./src'],
}
const sourceMapsConfiguration = [withSourceMaps, {}]
const cssConfiguration = [
withCSS,
{
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]',
},
},
]
const imagesConfiguration = [optimizedImages, {}]
const offlineConfiguration = withOffline
module.exports = withPlugins(
[sourceMapsConfiguration, imagesConfiguration, cssConfiguration, offlineConfiguration],
nextConfiguration
)