forked from RobinYang11/goji
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
122 lines (115 loc) · 2.59 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
const fs = require('fs');
const path = require('path')
const process = require('process');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");
const config = {
entry: "./src/_test.tsx",
mode: process.env.NODE_ENV === "development" ? "development" : "production",
output: {
filename: "[name].js",
publicPath: process.env.NODE_ENV === "development" ? "/" : "/static",
path: path.resolve(__dirname, "./test")
},
resolve: {
extensions: ['.js', '.tsx', '.jsx'],
fallback: {
'react/jsx-runtime': 'react/jsx-runtime.js',
'react/jsx-dev-runtime': 'react/jsx-dev-runtime.js',
},
alias: {
'@src': path.resolve(__dirname, './src'),
'@api': path.resolve(__dirname, './src/api'),
'@common': path.resolve(__dirname, './src/common'),
'@components': path.resolve(__dirname, './src/components'),
'@pages': path.resolve(__dirname, './src/pages'),
'@util': path.resolve(__dirname, './src/util'),
},
},
optimization: {
splitChunks: {
chunks: 'all',
},
},
devServer: {
static: {
directory: path.join(__dirname, 'dist')
},
host: "127.0.0.1",
hot: true, //热更新
open: true,
compress: true, // 静态资源 开启gzip 压缩
port: 3004, // devserver 启动端口
proxy: {
"/api": {
target: 'https://127.0.0.1:8001',
// changeOrigin: true,
secure: true,
pathRewrite: {
'/api': ''
}
}
}
},
module: {
rules: [
{
test: /\.(js|tsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript'
],
plugins: [
'transform-class-properties'
]
}
},
},
{
test: /\.(css|less)$/i, // 三个loader 都要安装
use: [
{ loader: "style-loader" },
{
loader: "css-loader",
},
{
loader: "less-loader",
options: {
lessOptions: {
modifyVars: {
'@primary-color': '#FFC300',
'link-color': '#FFC300',
'border-radius-base': '8px',
},
javascriptEnabled: true,
},
}
}
],
},
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve('./index.html')
}),
new CompressionPlugin({
include: /\/includes/,
}),
new webpack.LoaderOptionsPlugin({
options: {
assetPrefix: "https://app-test.zjhzoyad.com/material-prod/static/",
}
})
]
}
if (process.env.NODE_ENV === "development") {
config.devtool = "source-map"
}
module.exports = config;