-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnext.config.js
137 lines (121 loc) · 4.39 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
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const withSass = require('@zeit/next-sass');
const withImages = require('next-images');
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer');
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
// Set default plan identifier
process.env.PLAN_IDENTIFIER = process.env.PLAN_IDENTIFIER || 'hnh2035';
function getAllThemes() {
const styleDir = path.join(__dirname, 'styles');
return fs.readdirSync(styleDir).filter((item) => {
if (item === 'app') return false;
return fs.lstatSync(path.join(styleDir, item)).isDirectory();
});
}
const themes = getAllThemes();
const config = withBundleAnalyzer(withImages(withSass({
env: {
SENTRY_DSN: process.env.SENTRY_DSN,
},
publicRuntimeConfig: { // Will be available on both server and client
aplansApiBaseURL: process.env.APLANS_API_BASE_URL || 'https://aplans.api.hel.ninja/v1',
kerrokantasiApiBaseURL: process.env.KERROKANTASI_API_BASE_URL || 'https://api.hel.fi/kerrokantasi-test/v1',
// the default value for PLAN_IDENTIFIER is set below in webpack config
planIdentifier: process.env.PLAN_IDENTIFIER,
instanceType: process.env.INSTANCE_TYPE || 'development',
matomoURL: process.env.MATOMO_URL,
matomoSiteId: process.env.MATOMO_SITE_ID,
},
experimental: {
modern: true,
},
/*
manifest: {
// if src value is exist, icon image will be generated from src image, and ovwewritten
// icons value exist in the properties. if you want to keep your own icons path? do not pass
// src path to this plugin
name: 'Hiilineutraali Helsinki 2035',
short_name: 'CNH',
start_url: '/',
background_color: '#009246',
theme_color: '#009246',
display: 'minimal-ui',
icons: {
// source image path, to generate applications icons in 192x192, 512x512 sizes for manifest.
src: resolve(process.cwd(), './images/hel-icon.png'),
// default is true, cache images until the hash value of source image has changed
// if false, generating new icon images while every build time.
cache: true,
},
},
*/
analyzeServer: ['server', 'both'].includes(process.env.BUNDLE_ANALYZE),
analyzeBrowser: ['browser', 'both'].includes(process.env.BUNDLE_ANALYZE),
bundleAnalyzerConfig: {
server: {
analyzerMode: 'static',
reportFilename: '../bundles/server.html',
},
browser: {
analyzerMode: 'static',
reportFilename: '../bundles/client.html',
},
},
/* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["cfg"] }] */
webpack(cfg, options) {
const { isServer, buildId, dev } = options;
cfg.plugins.push(
new webpack.DefinePlugin({
'process.env.SENTRY_RELEASE': JSON.stringify(buildId),
}),
);
if (!isServer) {
cfg.resolve.alias['@sentry/node'] = '@sentry/browser';
}
// Ignore all locale files of moment.js
cfg.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
// If there is a separate theme for PLAN_IDENTIFIER, use that, otherwise
// use the default theme.
const defaultThemeIdentifier = themes.indexOf(process.env.PLAN_IDENTIFIER) >= 0
? process.env.PLAN_IDENTIFIER : 'default';
cfg.plugins.push(new webpack.EnvironmentPlugin({
PLAN_IDENTIFIER: '',
THEME_IDENTIFIER: defaultThemeIdentifier,
MATOMO_URL: '',
MATOMO_SITE_ID: '',
}));
// cfg.optimization.minimize = false;
// SOURCEMAPS
if (!dev && !isServer) {
cfg.devtool = 'source-map';
for (const plugin of cfg.plugins) {
if (plugin.constructor.name === 'UglifyJsPlugin') {
plugin.options.sourceMap = true;
break;
}
}
if (cfg.optimization && cfg.optimization.minimizer) {
for (const plugin of cfg.optimization.minimizer) {
if (plugin.constructor.name === 'TerserPlugin') {
plugin.options.sourceMap = true;
break;
}
}
}
if (process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_PROJECT && process.env.SENTRY_ORG) {
cfg.plugins.push(new SentryWebpackPlugin({
include: '.next',
ignore: ['node_modules'],
release: buildId,
rewrite: true,
stripCommonPrefix: true,
urlPrefix: '_next',
}));
}
}
return cfg;
},
})));
module.exports = config;