-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathuba.config.js
228 lines (215 loc) · 5.52 KB
/
uba.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
const path = require('path');
const hotMiddlewareScript = 'webpack-hot-middleware/client?reload=true';
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const svrConfig = {
historyApiFallback: false
};
// 远程代理访问,可以配置多个代理服务:https://github.com/chimurai/http-proxy-middleware
const proxyConfig = [
{
enable: true,
headers: {
// 这是之前网页的地址,从中可以看到当前请求页面的链接。
"Referer": "http://10.0.12.50:8080/wbalone/index-view.html"
},
// context,如果不配置,默认就是代理全部。
router: [
'/wbalone', '/iuap_pap_quickstart', '/iuap-example'
],
url: 'http://10.0.12.50:8080'
}
];
const globalEnvConfig = new webpack.DefinePlugin({
__MODE__: JSON.stringify(process.env.NODE_ENV),
GROBAL_HTTP_CTX: JSON.stringify("/iuap_pap_quickstart"),
GSP_CONTRACT: JSON.stringify("/gsp-contract"),
GSP_ORDERS: JSON.stringify("/gsp-orders"),
GSP_SUPPLIER: JSON.stringify("/gsp-supplier")
})
//提取package里的包
function getVendors() {
let pkg = require("./package.json");
let _vendors = [];
for (const key in pkg.dependencies) {
_vendors.push(key);
}
return _vendors;
}
//优化配置,对于使用CDN作为包资源的引用从外到内的配置
const externals = {
// 'axios': 'axios',
// 'react': 'React',
// 'react-dom': 'ReactDOM',
//'tinper-bee': 'TinperBee'
}
//默认加载扩展名、相对JS路径模块的配置
const resolve = {
extensions: [
'.jsx', '.js', '.less', '.css', '.json'
],
alias: {
components: path.resolve(__dirname, 'src/components/'),
modules: path.resolve(__dirname, 'src/modules/'),
routes: path.resolve(__dirname, 'src/routes/'),
layout: path.resolve(__dirname, 'src/layout/'),
utils: path.resolve(__dirname, 'src/utils/'),
static: path.resolve(__dirname, 'src/static/')
}
}
//开发和生产需要的loader
const rules = [{
test: /\.js[x]?$/,
exclude: /(node_modules)/,
include: path.resolve('src'),
use: [{
loader: 'babel-loader'
}]
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [{
loader: 'css-loader',
options: {
modules: false
}
}, 'postcss-loader'],
fallback: 'style-loader'
})
}, {
test: /\.less$/,
use: ExtractTextPlugin.extract({
use: [{
loader: 'css-loader',
options: {
modules: false
}
}, 'postcss-loader', 'less-loader'],
fallback: 'style-loader'
})
}, {
test: /\.(png|jpg|jpeg|gif)(\?.+)?$/,
//exclude: /favicon\.png$/,
use: [{
loader: 'url-loader',
options: {
limit: 8196,
name: 'images/[name].[hash:8].[ext]'
}
}]
}, {
test: /\.(eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
use: [{
loader: 'file-loader',
options: {
name: 'fonts/[name].[hash:8].[ext]'
}
}]
}]
//开发环境的webpack配置
const devConfig = {
devtool: 'cheap-module-eval-source-map',
entry: {
vendors: getVendors(),
app: ['babel-polyfill', './src/app.jsx', hotMiddlewareScript]
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'js/[name].[hash:8].js',
chunkFilename: 'js/[name].[hash:8].bundle.js',
publicPath: '/'
},
externals: externals,
module: {
rules: rules
},
plugins: [
new CommonsChunkPlugin({
name: "vendors"
}),
new ExtractTextPlugin({
filename: 'css/app.css'
}),
globalEnvConfig,
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
inject: 'body',
hash: false,
favicon: './src/static/images/favicon.png'
})
],
resolve: resolve
}
//生产环境的webpack配置
const prodConfig = {
devtool: 'source-map',
entry: {
vendors: getVendors(),
app: ['babel-polyfill', './src/app.jsx']
},
output: {
path: path.resolve(__dirname, './dist'),
chunkFilename: 'js/[name].[hash:8].bundle.js',
filename: 'js/[name].[hash:8].js'
},
externals: externals,
module: {
rules: rules
},
plugins: [
new CommonsChunkPlugin({
name: "vendors"
}),
new ExtractTextPlugin({
filename: 'css/app.css'
}),
globalEnvConfig,
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false,
drop_debugger: true,
drop_console: true
}
}),
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
inject: 'body',
hash: true,
favicon: './src/static/images/favicon.png',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static'
})
],
resolve: resolve
}
//最终向uba导出配置文件
module.exports = {
devConfig,
prodConfig,
svrConfig,
proxyConfig
};