forked from lhz516/hanzluo-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.client.js
126 lines (122 loc) · 3.66 KB
/
config.client.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
const webpack = require('webpack')
const path = require('path')
const AssetsPlugin = require('assets-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const { getWebpackDefinePlugin } = require('./utils')
const { DEV_SERVER_URL, PROD_ROOT_URL } = require('../constants')
const emptyFunc = () => {}
module.exports = (env = {}) => {
const isProd = !!env.prod
const isAnalysis = !!env.analysis
const mainEntry = ['./src/client/index.js']
if (!isProd) {
mainEntry.unshift(`webpack-hot-middleware/client?path=${DEV_SERVER_URL}__webpack_hmr&noInfo=true`)
}
return {
mode: isProd ? 'production' : 'development',
stats: 'errors-warnings',
target: 'web',
entry: {
main: mainEntry,
},
resolve: {
alias: {
// Temp solution for antd icons bundle size issue https://github.com/ant-design/ant-design/issues/12011
'@ant-design/icons/lib/dist$': path.resolve(__dirname, '../src/client/icons.js'),
},
},
output: {
path: path.resolve(__dirname, '../dist/client'),
filename: 'bundle-[hash].js',
chunkFilename: '[id][chunkhash].js',
publicPath: !isProd ? DEV_SERVER_URL : PROD_ROOT_URL,
},
module: {
rules: [
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
sourceMap: !isProd,
hmr: !isProd,
},
},
{
loader: 'css-loader',
options: {
sourceMap: !isProd,
},
},
{
loader: 'less-loader',
options: {
modifyVars: require('./antd.global'),
javascriptEnabled: true,
paths: [path.resolve(__dirname, 'node_modules')],
sourceMap: !isProd,
},
},
],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: isProd ? '> 1%, not dead' : { esmodules: true } }],
['@babel/preset-react'],
],
plugins: [
[
'import',
{
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
},
],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
],
},
},
},
],
},
plugins: [
new webpack.DefinePlugin(
getWebpackDefinePlugin({
__CLIENT__: true,
__SERVER__: false,
__DEV__: !isProd,
__PROD__: isProd,
})
),
new CopyPlugin([
{
from: 'src/server/public/',
to: 'public/',
},
]),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new AssetsPlugin({
filename: './dist/server/assets.json',
// fileTypes: ['js', 'css', 'jpg'],
}),
new webpack.HotModuleReplacementPlugin(),
isProd ? new CompressionPlugin() : emptyFunc,
isAnalysis ? new BundleAnalyzerPlugin() : emptyFunc,
],
devtool: !isProd ? 'cheap-module-source-map' : 'hidden-cheap-module-source-map',
}
}