forked from cardano-foundation/cardano-explorer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
executable file
·122 lines (113 loc) · 3.11 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
const withPlugins = require('next-compose-plugins');
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer');
const withFonts = require('next-fonts');
const withImages = require('next-images');
const withPrefresh = require('@prefresh/next');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const DefinePlugin = require('webpack').DefinePlugin;
require('dotenv').config();
const DEBUG = process.env.DEBUG;
const packageJson = require('./package.json');
const SUPPORTED_LOCALES = ['en', 'de', 'ja'];
module.exports = withPlugins(
[
[
withBundleAnalyzer,
{
analyzeBrowser: process.env.BUNDLE_ANALYZE === 'browser',
bundleAnalyzerConfig: {
browser: {
analyzerMode: 'static',
reportFilename: '../bundles/client.html',
},
},
},
],
[
withFonts,
{
enableSvg: true,
},
],
[
withImages,
{
inlineImageLimit: 5000,
},
],
[withPrefresh]
],
{
// Further customizations of webpack config:
distDir: '../build/.next',
env: {
DEBUG
},
webpack(config, options) {
if (options.isServer) {
config.externals = ['react', 'react-dom', 'react-ssr-prepass', ...config.externals]
}
// Alias react with Preact
config.resolve.alias = {
...config.resolve.alias,
'react': "preact/compat",
'react$': "preact/compat",
"react-dom": "preact/compat",
'react-dom$': 'preact/compat',
"react-ssr-prepass": "preact-ssr-prepass",
};
config.plugins.push(new LodashModuleReplacementPlugin());
// Push DotEnv vars into client code
config.plugins.push(
new Dotenv({
systemvars: true,
})
);
config.plugins.push(
new DefinePlugin({
'process.env': {
PACKAGE_HOMEPAGE: `"${packageJson.homepage}"`,
PACKAGE_VERSION: `"${packageJson.version}"`
}
}));
// Support GraphQL literals
config.module.rules.push({
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
use: [
{
loader: 'graphql-tag/loader',
},
],
});
return config;
},
experimental: {
modern: true,
},
exportTrailingSlash: false,
/**
* Generate language specific pages under /[locale]/... paths e.g:
* /de/ leads to the the German landing page
* /de/block leads to the German block page etc.
*
* @param defaultPathMap
* @returns {Promise<{}>}
*/
exportPathMap: async function(defaultPathMap) {
const pathMap = {};
Object.entries(defaultPathMap).forEach(([key, value]) => {
// Only generate language specific paths for localized routes
if (!key.includes('[locale]')) {
pathMap[key] = value;
return;
}
SUPPORTED_LOCALES.forEach(locale => {
pathMap[`${key.replace('[locale]', locale)}`] = { ...value, query: { locale } };
});
});
return pathMap;
},
},
);