-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.client.config.js
107 lines (103 loc) · 3.26 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
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
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpackMerge = require('webpack-merge');
const webpack = require('webpack');
const { BUILD_FOLDER, PUBLIC_FOLDER, JS_FOLDER, IMAGES_FOLDER } = require('./utils/server.config');
const modeConfig = mode => require(`./utils/build/webpack.client.${mode}.config`)(mode);
const presetConfig = require('./utils/build/loadPresets');
module.exports = ({ mode, presets } = { mode: 'production', presets: [] }) => {
console.log(`[webpack.client.config] Executing in ${mode} mode with ${presets || 'no'} presets`); // eslint-disable-line no-console
return webpackMerge(
{
mode,
target: 'web',
entry: ['./web/client.tsx'],
output: {
filename: `${JS_FOLDER}/client.js`,
path: path.join(__dirname, BUILD_FOLDER, PUBLIC_FOLDER)
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: ['babel-loader', 'awesome-typescript-loader']
},
{
enforce: 'pre',
test: /\.js$/,
use: 'source-map-loader'
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[name].[ext]',
outputPath: path.join(__dirname, BUILD_FOLDER, PUBLIC_FOLDER, IMAGES_FOLDER),
publicPath: '/'
}
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: false,
mozjpeg: {
progressive: true,
quality: 100
},
webp: {
quality: 100
}
}
}
]
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
publicPath: '/'
}
},
include: [path.resolve(__dirname, 'web/fonts')]
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
BUILD_TARGET: JSON.stringify('client')
}
}),
new HtmlWebPackPlugin({
template: './web/index.html',
favicon: `./web/${IMAGES_FOLDER}/favicon.ico`
}),
new webpack.NoEmitOnErrorsPlugin(),
new CopyWebpackPlugin([{ from: 'web/images', to: 'images' }])
],
resolve: {
extensions: ['.js', '.ts', '.tsx'],
alias: {
components: path.resolve(__dirname, 'web/components/'),
images: path.resolve(__dirname, 'web/images/'),
state: path.resolve(__dirname, 'web/state/'),
styles: path.resolve(__dirname, 'web/styles/'),
utils: path.resolve(__dirname, 'utils/')
}
}
},
modeConfig(mode),
presetConfig({ mode, presets: presets || [] })
);
};