-
Notifications
You must be signed in to change notification settings - Fork 11
/
next.config.js
108 lines (98 loc) · 3.17 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
'use strict';
const { withRasterImages, withPlayback, withSVG, withFonts, with3D, withJSON5 } = require('@moxy/next-common-files');
const withOneOf = require('@moxy/next-webpack-oneof');
const withCompileNodeModules = require('@moxy/next-compile-node-modules');
const withPlugins = require('next-compose-plugins');
const withSitemap = require('@moxy/next-sitemaps/plugin');
const envVar = require('env-var');
const { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } = require('next/constants');
const { locales, defaultLocale } = require('./intl');
const isEnvRequired = (phase) => phase === PHASE_DEVELOPMENT_SERVER || phase === PHASE_PRODUCTION_BUILD;
const extEnvVar = envVar.from(process.env, {
asStringWithPattern(value, regExp) {
const valid = regExp.test(value);
if (!valid) {
throw new Error(`should match pattern ${regExp.toString()}`);
}
return value;
},
});
module.exports = (phase, params) => {
const COMPRESSION = extEnvVar.get('COMPRESSION').asBool();
const GTM_CONTAINER_ID = extEnvVar.get('GTM_CONTAINER_ID').asString();
const SITE_URL = extEnvVar.get('SITE_URL')
.required(isEnvRequired(phase))
.asStringWithPattern(/^https?:\/\/.+[^/]$/);
return withPlugins([
withOneOf,
withRasterImages(),
withRasterImages({
include: /\.data-url\./,
options: {
limit: Infinity,
},
}),
withPlayback(),
withPlayback({
include: /\.data-url\./,
options: {
limit: Infinity,
},
}),
withFonts(),
withFonts({
include: /\.data-url\./,
options: {
limit: Infinity,
},
}),
with3D(),
with3D({
include: /\.data-url\./,
options: {
limit: Infinity,
},
}),
withSVG(),
withSVG({
include: /\.data-url\./,
options: {
limit: Infinity,
},
}),
withSVG({
include: /\.inline\./,
inline: true,
}),
withJSON5(),
withCompileNodeModules(),
withSitemap(phase, SITE_URL),
// Base config here.
// Please note that the `nextConfig` variable contains the config after all plugins have run,
// so be sure to merge it correctly.
(nextConfig) => ({
...nextConfig,
poweredByHeader: false,
compress: COMPRESSION,
eslint: {
ignoreDuringBuilds: true,
},
i18n: {
locales: locales.map(({ tag }) => tag),
defaultLocale,
},
env: {
...nextConfig.env,
GTM_CONTAINER_ID,
SITE_URL,
},
webpack: (config, options) => {
// Customize webpack config here..
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
}),
])(phase, params);
};