-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.client.config.js
77 lines (73 loc) · 2.01 KB
/
webpack.client.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
const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const LoadablePlugin = require('@loadable/webpack-plugin')
const devMode = process.env.NODE_ENV !== 'production'
const hotMiddlewareScript = `webpack-hot-middleware/client?name=web&log=false&reload=true`
const getEntryPoint = (target) => {
if (target === 'node') {
return ['./src/index.tsx']
}
return devMode
? [hotMiddlewareScript, './src/index.tsx']
: ['./src/index.tsx']
}
const getConfig = (target) => {
return {
mode: devMode ? 'development' : 'production',
name: target,
target,
devtool: devMode ? 'inline-source-map' : false,
entry: getEntryPoint(target),
output: {
path: path.resolve(__dirname, `dist/${target}`),
filename: '[name].js',
publicPath: '/web/',
libraryTarget: target === 'node' ? 'commonjs2' : undefined,
},
module: {
rules: [
{
test: /\.s?css$/i,
exclude: /\.module\.s?css$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
}, // CSS Module ([filename].module.css)
{
test: /\.module\.s?css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
},
},
'postcss-loader',
'sass-loader',
],
},
{
test: /\.jsx?$|\.tsx?$/,
use: 'babel-loader',
},
],
},
resolve: {
extensions: ['.js', '.ts', '.tsx', '.jsx'],
},
plugins:
target === 'web'
? [
new webpack.HotModuleReplacementPlugin(),
new LoadablePlugin(),
new MiniCssExtractPlugin(),
]
: [new LoadablePlugin(), new MiniCssExtractPlugin()],
}
}
module.exports = [getConfig('web'), getConfig('node')]