-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
139 lines (139 loc) · 4.53 KB
/
webpack.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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {proxyPort, apiServer} = require("./bin/config");
module.exports = {
cache:true,
devtool: 'cheap-module-source-map',
entry: {
production: path.resolve(__dirname, './views/app.jsx'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/[name].js',
publicPath: '/',
chunkFilename: 'js/[name].js',
},
resolve: {
extensions: ['.js', '.json', '.jsx','.ts','.tsx'],
alias: {
'@':path.resolve(__dirname,'views'),
},
},
module: {
rules: [
{
test: /\.ts?$/,
use: [
{
loader: 'babel-loader',
options:{
presets: ['@babel/preset-env','@babel/preset-react','@babel/preset-typescript'],
}
}
,'ts-loader'],
include: [path.resolve(__dirname, 'views')],
},
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options:{
presets: ['@babel/preset-env','@babel/preset-react','@babel/preset-typescript'],
}
}
,'ts-loader'],
include: [path.resolve(__dirname, 'views')],
},
{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
options: {
presets:['@babel/preset-env','@babel/preset-react']
},
},
include: [path.resolve(__dirname, 'views')],
},
{
test: /\.css$/,
include: [path.resolve(__dirname, 'views'),path.resolve(__dirname, 'node_modules/@wangeditor'),path.resolve(__dirname, 'node_modules/swiper')],
use: ['style-loader',
{
loader:'css-loader',
options:{
modules:false,
}
},
],
},
{ test: /\.less$/, exclude: /node_modules/,
use: [
'style-loader',
{
loader:'css-loader',
options:{
modules:true,
}
},
{
loader: "less-loader",
options:{},
},
]
},
{
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 100,
name: 'asset/[name].[ext]',
esModule:false
},
},
],
},
],
},
mode: 'development',
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, './views/index.ejs'),
inject: 'body',
hase: true,
minify: {
// 压缩HTML文件
removeComments: false, // 移除HTML中的注释
collapseWhitespace: false, // 删除空白符与换行符
},
chunks: ['production'],
}),
],
devServer: {
port: proxyPort, // 前端代理端口
static: path.resolve(__dirname, 'dist'), // 临时的打包目录(在内存中)
historyApiFallback: true, // 启用历史API回退
hot: true,
open: true,
compress:false,
client:{
overlay:{
runtimeErrors:(error)=> error.message !== "ResizeObserver loop limit exceeded"
}
},
proxy:{
'/api':{
target: `${apiServer}`, // 后端服务地址
changeOrigin: true,
},
'/services':{
target: `${apiServer}`, // 后端服务地址
changeOrigin: true,
}
}
}
};