-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.client.config.js
52 lines (48 loc) · 1.5 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
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: /\.css?$/,
exclude: [],
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-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')]