-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (91 loc) · 2.37 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
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isDev = (mode) => mode === 'development';
const isProd = (mode) => mode === 'production';
module.exports = (_, argv) => ({
entry: [
...(isDev(argv.mode) ? ['webpack-hot-middleware/client'] : []),
'./client/index.ts',
'./client/index.scss',
],
output: {
path: path.resolve(__dirname, './public'),
filename: '[name].js',
},
mode: argv.mode,
devtool: isDev(argv.mode) ? 'source-map' : 'cheap-source-map',
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{ loader: 'babel-loader' },
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.client.json',
},
},
],
},
{
test: /\.(sa|sc|c)ss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 2 },
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
ident: 'postcss',
plugins: [autoprefixer()].concat(
isProd(argv.mode) ? [cssnano()] : []
),
},
},
},
'sass-loader',
],
},
{
test: /\.svg$/,
exclude: /node_modules/,
use: 'svg-inline-loader',
},
],
},
resolve: {
alias: {
'@bingo/common': path.resolve(__dirname, './common'),
'@bingo/components': path.resolve(__dirname, './client/components'),
'@bingo/client': path.resolve(__dirname, './client'),
},
extensions: ['.ts', '.js', '.css'],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new CleanWebpackPlugin({
verbose: isDev(argv.mode),
cleanOnceBeforeBuildPatterns: ['artifacts', '*.gz', '*.js', '*.css'],
}),
new webpack.EnvironmentPlugin({
NODE_ENV: argv.mode,
}),
new webpack.HotModuleReplacementPlugin(),
],
stats: {
colors: true,
},
});