-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.dev.js
More file actions
143 lines (143 loc) · 3.5 KB
/
webpack.dev.js
File metadata and controls
143 lines (143 loc) · 3.5 KB
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
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$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer')({
browsers: [
'iOS >= 7',
'Android >= 4.1',
'last 10 Chrome versions',
'last 10 Firefox versions',
'Safari >= 6',
'ie > 8',
],
}),
],
},
},
],
},
{
test: /.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'less-loader',
options: {
modifyVars: {
'@brand-primary': '#FF9000',
'@color-text-base': '#FF9000',
'@primary-button-fill': '#FF9000',
'@primary-button-fill-tap': '#FF9000',
},
javascriptEnabled: true,
},
},
],
},
{
test: /\.(png|jpg|gif|woff|svg|eot|woff2|tff)$/,
use: 'url-loader?limit=8129', //limit的参数,当你图片大小小于这个限制的时候,会自动启用base64编码图片
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.css', '.less', '.sass'],
},
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: 8888,
watchContentBase: true,
watchOptions: {
poll: true,
},
proxy: {
'/api/www/': {
target: 'http://wwwwww.com',
changeOrigin: true,
pathRewrite: {
'^/api/jedishareservice': '/api/jedishareservice',
},
},
'/api/mbff/': {
target: 'http://wwwwww.com',
changeOrigin: true,
pathRewrite: {
'^/api/mbff': '/api/mbff',
},
},
},
overlay: true,
historyApiFallback: {
index: '/index.html',
},
},
}