-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnext.config.js
67 lines (58 loc) · 1.92 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
/** @type {import('next').NextConfig} */
const webpack = require('webpack');
const path = require('path');
const nextTranslate = require('next-translate-plugin');
// 获取当前开发环境
const NODE_ENV = process.env.APP_ENV || 'prod';
// 根据环境创建打包目录
const BUILD_FOLDER = (() => {
if (NODE_ENV !== 'dev') return 'dist';
return '.next';
})();
// 配置别名
const aliases = {
'@public': path.resolve('./public'),
'@src': path.resolve('./src'),
'@styles': path.resolve('./styles'),
'@components': path.resolve('./src/components'),
'@constants': path.resolve('./src/constants'),
'@service': path.resolve('./src/service'),
'@static': path.resolve('./src/static'),
'@store': path.resolve('./src/store'),
'@utils': path.resolve('./src/utils'),
'@views': path.resolve('./src/views')
};
module.exports = nextTranslate({
// reactStrictMode: true,
swcMinify: true,
images: {
unoptimized: true,
},
distDir: BUILD_FOLDER,
// webpack 配置项
webpack (config) {
// 配置别名
config.resolve.alias = Object.assign({}, config.resolve.alias, aliases);
// 修复对fs包的依赖
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
path: false
};
// 配置环境变量
config.plugins.push(
new webpack.DefinePlugin({
__ENV__: JSON.stringify(NODE_ENV),
__NODE_ENV__: JSON.stringify({
apiDomain: process.env.API_URL,
apiDomainFuture: process.env.API_FUTURES,
websiteDomain: process.env.WEBSITE_URL,
WebSocketDomain: process.env.WEBSOCKET_URL,
staticDomain: process.env.STATIC_URL,
cookieDomain: process.env.COOKIES_DOMIAN
})
})
)
return config;
}
});