-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.umirc.js
172 lines (168 loc) · 4.6 KB
/
.umirc.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
var path = require('path');
var CompressionPlugin = require('compression-webpack-plugin');
var env = process.env.QA_ENV;
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';
function getPlugins() {
if (env === 'build') {
return {
install: {
plugin: require('uglifyjs-webpack-plugin'),
args: [
{
sourceMap: false,
uglifyOptions: {
compress: {
// 删除所有的 `console` 语句
drop_console: true,
},
output: {
// 最紧凑的输出
beautify: false,
// 删除所有的注释
comments: false,
},
},
},
],
},
};
} else {
return {};
}
}
function getModulePackageName(module) {
if (!module.context) return null;
const nodeModulesPath = path.join(__dirname, './node_modules/');
if (module.context.substring(0, nodeModulesPath.length) !== nodeModulesPath) {
return null;
}
const moduleRelativePath = module.context.substring(nodeModulesPath.length);
const [moduleDirName] = moduleRelativePath.split(path.sep);
let packageName = moduleDirName;
// handle tree shaking
if (packageName.match('^_')) {
// eslint-disable-next-line prefer-destructuring
packageName = packageName.match(/^_(@?[^@]+)/)[1];
}
if (packageName.match(/cesium/)) {
// eslint-disable-next-line prefer-destructuring
packageName = 'cesium';
}
if (packageName.match(/jsoneditor|brace/)) {
// eslint-disable-next-line prefer-destructuring
packageName = 'jsoneditor';
}
return packageName;
}
// ref: https://umijs.org/config/
export default {
// treeShaking: true,
define: {
CESIUM_BASE_URL: '/cesium',
},
routes: [
{
path: '/',
component: '../layouts/index',
routes: [
{ path: '/', component: '../pages/index' }
]
}
],
plugins: [
// ref: https://umijs.org/plugin/umi-plugin-react.html
['umi-plugin-react', {
antd: true,
dva: true,
dynamicImport: { webpackChunkName: true },
title: 'react-3D-Wind',
dll: false,
locale: {
enable: true,
default: 'en-US',
},
routes: {
exclude: [
/models\//,
/services\//,
/model\.(t|j)sx?$/,
/service\.(t|j)sx?$/,
/components\//,
],
},
}],
],
publicPath: '/',
alias: {
'cesium': path.resolve(__dirname, './node_modules/cesium/Source'),
'@components': path.resolve(__dirname, './src/components'),
'@utils': path.resolve(__dirname, './src/utils'),
'@images': path.resolve(__dirname, './src/assets/images'),
'@services': path.resolve(__dirname, './src/services'),
'@config': path.resolve(__dirname, './src/assets/config'),
},
'copy': [
{
from: path.join(cesiumSource, cesiumWorkers), to: 'cesium/Workers',
},
{
from: path.join(cesiumSource, 'Assets'), to: 'cesium/Assets',
},
{
from: path.join(cesiumSource, 'Widgets'), to: 'cesium/Widgets',
},
],
chainWebpack(config, { webpack }) {
config.merge({
amd: {
toUrlUndefined: true,
},
node: {
fs: 'empty',
},
module: {
unknownContextCritical: false,
},
plugin: getPlugins(),
});
if (env === 'build') {
config.optimization
.runtimeChunk(false) // share the same chunks across different modules
.splitChunks({
chunks: 'async',
name: 'vendors',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendors: {
test: module => {
const packageName = getModulePackageName(module);
if (packageName) {
return ['cesium', 'jsoneditor'].indexOf(packageName) >= 0;
}
return false;
},
name(module) {
const packageName = getModulePackageName(module);
if (['cesium'].indexOf(packageName) >= 0) {
return 'cesium'; // visualization package
}
if (['jsoneditor'].indexOf(packageName) >= 0) {
return 'jsoneditor'; // visualization package
}
return 'misc';
},
},
},
});
config.plugin('compression').use(
new CompressionPlugin({
test: /\.(js|css)(\?.*)?$/i,
filename: '[path].gz[query]',
algorithm: 'gzip',
}),
);
}
}
}