This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathnext.config.js
109 lines (99 loc) · 2.29 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-disable @typescript-eslint/no-var-requires */
// const withBundleAnalyzer = require('@next/bundle-analyzer')
const withPlugins = require('next-compose-plugins')
const path = require('path')
const Dotenv = require('dotenv-webpack')
// Required by Docker
require('dotenv').config()
const nextConfig = {
target: 'server',
webpack: (config, { isServer }) => {
if (!isServer) {
config.node = {
fs: 'empty'
}
} else {
config.node = {
'node-hid': 'empty'
}
}
config.plugins = config.plugins || []
config.plugins = [
...config.plugins,
// Read the .env file
new Dotenv({
path: path.join(__dirname, '.env'),
systemvars: true // Required by Docker
})
]
config.module.rules.push(
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
},
{
test: /\.(raw)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'raw-loader'
},
{
test: /\.md$/,
use: [
'html-loader',
'markdown-loader'
]
},
{
test: /\.(png|svg|eot|otf|ttf|woff|woff2|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 8192,
publicPath: '/_next/static/',
outputPath: 'static/',
name: '[name].[ext]'
}
}
}
)
return config
}
}
module.exports = withPlugins([],
{
...nextConfig,
async redirects () {
const spaceId = ':spaceId(\\d{1,}|@.*)'
const slug = ':slug(.*\\d{1,})*'
const spacePage = '/:spaceId*'
const postPage = '/:spaceId/:slug*'
// Redirects for all URL formats. DO NOT REMOVE!
return [
{
source: '/spaces/all',
destination: '/spaces',
permanent: true,
},
{
source: `/spaces/${spaceId}/posts/${slug}`,
destination: postPage,
permanent: true,
},
{
source: `/spaces/${spaceId}/about`,
destination: `${spacePage}/about`,
permanent: true,
},
{
source: `/spaces/${spaceId}`,
destination: spacePage,
permanent: true,
},
{
source: `/${spaceId}/posts/${slug}`,
destination: postPage,
permanent: true,
}
]
}
})