forked from fumeboy/RelaxedUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
150 lines (150 loc) · 4.91 KB
/
webpack.config.ts
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
const HtmlWebPackPlugin = require('html-webpack-plugin');
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
module.exports = {
output: {
publicPath: '/',
filename: '[name]_[chunkhash:8].js',
path: path.resolve(__dirname, './build'),
},
module: {
rules: [
{
test: /\.ts|.tsx?$/,
exclude: /node_modules/,
loader: 'babel-loader!awesome-typescript-loader',
},
{
test: /\.jsx|.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer')({
Babel: [
'iOS >= 7',
'Android >= 4.1',
'last 10 Chrome versions',
'last 10 Firefox versions',
'Safari >= 6',
'ie > 8',
],
}),
],
},
},
],
},
{
test: [/\.less$/],
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
localIdentName: "[name]__[local]___[hash:base64:5]",
},
}
},
{
loader: 'less-loader',
options: {
importLoaders: 2,
modules: true,
localIdentName: "[name]_[local]_[hash:base64:5]",
javascriptEnabled: true,
},
},
],
},
{
test: /\.(png|jpg|gif|woff|svg|eot|woff2|tff)$/,
use: 'url-loader?limit=8129', //limit的参数,当你图片大小小于这个限制的时候,会自动启用base64编码图片
exclude: /node_modules/,
},
],
},
resolve: {
alias: {
'$': path.join(__dirname, 'src'),
'$u': path.join(__dirname, 'src/components/UI'),
},
extensions: ['.ts', '.tsx', '.js', '.json', '.css', '.less'],
},
plugins: [
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html',
}),
new UglifyJsPlugin({sourceMap: true}),
new CleanWebpackPlugin(),
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
chunks: 'initial',
minChunks: 2,
maxInitialRequests: 5,
minSize: 0,
},
vendor: {
// 将第三方模块提取出来
// test: /node_modules/,
chunks: 'initial',
test: /react|lodash/, // 正则规则验证,如果符合就提取 chunk
name: 'vendor',
priority: 10, // 优先
enforce: true,
},
},
},
},
devServer: {
contentBase: path.join(__dirname, '/'),
compress: true,
publicPath: '/',
port: 8808,
watchContentBase: true,
watchOptions: {
poll: true,
},
proxy: {
'/api/jedishareservice/': {
target: 'http://share.dev.qiaofangyun.com',
changeOrigin: true,
pathRewrite: {
'^/api/jedishareservice': '/api/jedishareservice',
},
},
'/api/mbff/': {
target: 'http://nm.dev.qiaofangyun.com',
changeOrigin: true,
pathRewrite: {
'^/api/mbff': '/api/mbff',
},
},
},
overlay: true,
historyApiFallback: {
index: '/index.html',
},
},
};