-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
163 lines (136 loc) · 3.68 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*!
* Notiflix
* Description: Next.js configuration.
* Version: 1.0.0
* Author: Furkan ('https://github.com/furcan')
* Copyright 2019-Present Notiflix, GPL-3.0 License ('https://opensource.org/licenses/GPL-3.0')
*/
// Dependencies
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const StylelintPlugin = require('stylelint-webpack-plugin');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { constants } = require('./.dev/src/application/constants');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { routes } = require('./.dev/src/application/routes');
// Constants: begin
const isDev = process.env.NODE_ENV === 'development';
const isProd = process.env.NODE_ENV === 'production';
const appUrl = isProd ? constants.app.url : '';
const appName = constants.app.name;
const appVersion = constants.app.version;
const appOgImagePath = constants.app.ogImagePath;
// Constants: end
// Next Config: begin
/** @type {import('next').NextConfig} */
const nextConfig = {
// ts
typescript: {
ignoreBuildErrors: false,
},
// eslint
eslint: {
ignoreDuringBuilds: false,
dirs: ['src'],
},
// next images
images: {
loader: 'imgix',
path: appUrl,
disableStaticImages: true,
},
// enable/disable gzip
compress: true,
// add/remove "x-powered-by"
poweredByHeader: false,
// add/remove "/" to URLs
trailingSlash: false,
// custom env
env: {
isDev,
isProd,
appUrl,
appName,
appVersion,
appOgImagePath,
},
// assets prefix
assetPrefix: appUrl,
// extensions
pageExtensions: ['jsx', 'js', 'ts', 'tsx'],
// dist directory
distDir: '.build',
// sass
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
},
// useless with next export
redirects: async () => {
return [
{
source: '/home',
destination: '/',
permanent: false,
},
{
source: '/redirect-me',
destination: '/redirect-to',
permanent: false,
},
];
},
// static paths
exportPathMap: async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
defaultPathMap,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{ dev, dir, outDir, distDir, buildId },
) => {
let defaultPaths = {
'/': { page: '/home' },
'/404': { page: '/404' },
'/500': { page: '/500' },
};
routes?.filter(route => route?.isActive && route?.addToNextJSConfig)?.map(route => {
const routePath = {
[route?.pathAs]: { page: route?.pathPage },
};
defaultPaths = { ...defaultPaths, ...routePath };
});
return defaultPaths;
},
// Build ID
generateBuildId: async () => process.env.BUILD_ID || `BID-${new Date().getTime()}`,
// Webpack config
webpack: (config, { isServer }) => {
// frontmatter markdown loader
config.module.rules.push(
{
test: /\.md$/,
loader: 'frontmatter-markdown-loader',
},
);
// Fixes npm packages that depend on "fs" module
if (!isServer) {
config.resolve.fallback.fs = false;
}
// eslint
config.plugins.push(new ForkTsCheckerWebpackPlugin({
eslint: {
files: './src/**/*.{ts,tsx,js,jsx}',
memoryLimit: 8192,
},
}));
// stylelint
config.plugins.push(new StylelintPlugin({
files: './src/**/*.scss',
}));
// return extended config
return config;
},
};
// Next Config: end
module.exports = nextConfig;