This repository was archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
183 lines (169 loc) · 5.57 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* eslint-disable @typescript-eslint/no-var-requires */
const packagejson = require('./package.json')
const withPlugins = require('next-compose-plugins')
const { IgnorePlugin, DefinePlugin } = require('webpack')
const {
PHASE_PRODUCTION_BUILD,
PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_SERVER,
PHASE_DEVELOPMENT_BUILD,
} = require('next/constants')
const withCSS = require('@zeit/next-css')
const withLess = require('@zeit/next-less')
const withSass = require('@zeit/next-sass')
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer')
const withNextRuntimeDotenv = require('next-runtime-dotenv')
const createResolver = require('postcss-import-webpack-resolver')
const withOptimizedImages = require('next-optimized-images')
const path = require('path')
/* eslint-enable @typescript-eslint/no-var-requires */
// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
require.extensions['.less'] = file => {}
}
let aliases = {}
Object.entries(packagejson._moduleAliases || {}).forEach(([k, v]) => {
aliases[k] = path.resolve(__dirname, v)
})
const withConfig = withNextRuntimeDotenv({
public: ['API_URL', 'API_KEY', 'RUNNING', 'SESSION_KEYS'],
server: [
'MONGODB_URL',
'REDIS_URL',
'ELASTIC_URL',
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_KEY',
'AWS_BUCKET_NAME',
'PRIMUS_1_PORT',
'PRIMUS_1_HOST',
'FACEBOOK_APP_SECRET',
'FACEBOOK_APP_ID',
'GOOGLE_CLIENT_ID',
'GOOGLE_CLIENT_SECRET',
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_KEY',
'AWS_BUCKET_NAME',
'AWS_S3_ENDPOINT',
'EMAIL_DOMAIN',
'EMAIL_HOST',
'EMAIL_PORT',
'EMAIL_SECURE',
'EMAIL_USER',
'EMAIL_PASS',
'JWT_KEY',
],
})
const webpack_config = (config, { dev, isServer }) => {
const prod = !dev
//config.plugins.push(new Dotenv({ path: './public.env' }));
config.plugins.push(new IgnorePlugin(/^\.\/locale$/, /moment$/))
// config.plugins.push(new DefinePlugin({
// __RSUITE_CLASSNAME_PREFIX__: JSON.stringify('komplent-')
// }));
Object.assign(config.resolve.alias, aliases)
// if (dev) {
// config.module.rules.push({
// test: /\.(jsx?|gql|graphql)$/,
// loader: 'eslint-loader',
// exclude: ['/node_modules/', '/.next/', '/build/', '/scripts/'],
// enforce: 'pre'
// });
// }
if (prod) {
config.plugins = config.plugins.filter(plugin => {
if (plugin.constructor.name === 'ForkTsCheckerWebpackPlugin')
return false
return true
})
}
return config
}
let next_config = {
poweredByHeader: false,
distDir: 'build',
webpack: webpack_config,
typescript: {
ignoreDevErrors: true,
ignoreBuildErrors: true,
},
}
module.exports = withConfig(
withPlugins(
[
[
withOptimizedImages,
{
// svgSpriteLoader: {
// spriteModule: require.resolve('svg-sprite-loader/runtime/browser-sprite.build'),
// symbolModule: require.resolve('svg-baker-runtime/browser-symbol'),
// }
},
],
[
withSass,
{
postcssLoaderOptions: {
config: {
ctx: {
'postcss-import': {
resolve: createResolver({
// use aliases defined in config
alias: aliases,
// include where to look for modules
modules: ['.', 'node_modules'],
}),
},
// theme: JSON.stringify(process.env.REACT_APP_THEME)
},
},
},
},
],
[
withCSS,
{
cssLoaderOptions: {
importLoaders: 1,
},
},
],
[
withLess,
{
lessLoaderOptions: {
javascriptEnabled: true,
localIdentName: '[local]___[hash:base64:5]',
},
},
],
[
withBundleAnalyzer,
{
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',
},
},
},
],
],
{
...next_config,
[PHASE_PRODUCTION_BUILD]: {},
[PHASE_PRODUCTION_SERVER]: {},
[PHASE_DEVELOPMENT_SERVER]: {},
['!' + PHASE_DEVELOPMENT_SERVER]: {},
}
)
)