forked from rsuite/rsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
134 lines (118 loc) · 3.48 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
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const webpack = require('webpack');
const withImages = require('next-images');
const withPlugins = require('next-compose-plugins');
const pkg = require('./package.json');
const findPages = require('./scripts/findPages');
const markdownRenderer = require('./scripts/markdownRenderer');
const resolveToStaticPath = relativePath => path.resolve(__dirname, relativePath);
const SVG_LOGO_PATH = resolveToStaticPath('./resources/images');
const __DEV__ = process.env.NODE_ENV !== 'production';
const RSUITE_ROOT = path.join(__dirname, '../src');
const LANGUAGES = {
// key: [language, path]
default: ['en', ''],
en: ['en', '/en'],
zh: ['zh', '/zh']
};
const getLanguage = language => LANGUAGES[language] || '';
module.exports = withPlugins([[withImages]], {
webpack(config) {
const originEntry = config.entry;
config.module.rules.unshift({
test: /\.svg$/,
include: SVG_LOGO_PATH,
use: [
{
loader: 'babel-loader'
},
{
loader: '@svgr/webpack',
options: {
babel: false,
icon: true
}
}
]
});
config.module.rules.push({
test: /\.ts|tsx?$/,
use: ['babel-loader?babelrc'],
include: [RSUITE_ROOT, path.join(__dirname, './')],
exclude: /node_modules/
});
config.module.rules.push({
test: /\.md$/,
use: [
{
loader: 'html-loader'
},
{
loader: 'markdown-loader',
options: {
pedantic: true,
renderer: markdownRenderer([
'javascript',
'bash',
'xml',
'css',
'less',
'json',
'diff',
'typescript'
])
}
}
]
});
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
'process.env': {
__DEV__: JSON.stringify(__DEV__),
VERSION: JSON.stringify(pkg.version)
}
})
]);
config.resolve.alias['@'] = resolveToStaticPath('./');
config.resolve.alias['rsuite'] = resolveToStaticPath('../src');
config.resolve.alias['@rsuite-locales'] = resolveToStaticPath(
'./node_modules/rsuite/lib/locales'
);
config.entry = async () => {
const entries = await originEntry();
if (entries['main.js'] && !entries['main.js'].includes('./client/polyfills.ts')) {
entries['main.js'].unshift('./client/polyfills.ts');
}
return entries;
};
return config;
},
exportTrailingSlash: true,
exportPathMap: () => {
const pages = findPages();
const map = {};
function traverse(nextPages, userLanguage) {
const [language, rootPath] = getLanguage(userLanguage);
nextPages.forEach(page => {
if (page.children.length === 0) {
map[`${rootPath}${page.pathname}`] = {
page: page.pathname,
query: { userLanguage: language }
};
return;
}
traverse(page.children, userLanguage);
});
}
Object.keys(LANGUAGES).forEach(key => traverse(pages, key));
return map;
},
exclude: SVG_LOGO_PATH,
onDemandEntries: {
// Period (in ms) where the server will keep pages in the buffer
maxInactiveAge: 120 * 1e3, // default 25s
// Number of pages that should be kept simultaneously without being disposed
pagesBufferLength: 3 // default 2
}
});