-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
109 lines (107 loc) · 2.18 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import path from 'path';
import url from 'url';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { transform } from '@karuta/linguist';
import api from '@asmodee/werewolf-server';
const rootDir = path.dirname(url.fileURLToPath(import.meta.url));
/**
* @return {import('webpack').Configuration} Webpack configuration
*/
export default function config(env, argv) {
const mode = argv && argv.mode === 'development' ? 'development' : 'production';
return {
mode,
entry: {
app: './src/index.tsx',
},
output: {
filename: 'static/[name].js',
path: path.resolve(rootDir, 'dist'),
},
resolveLoader: {
modules: [path.resolve(rootDir, 'node_modules')],
},
resolve: {
extensions: [
'.ts',
'.tsx',
'.js',
],
alias: {
'@formatjs/icu-messageformat-parser': '@formatjs/icu-messageformat-parser/no-parser',
},
},
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /node_modules/,
name: 'vendor',
enforce: true,
chunks: 'all',
},
},
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
getCustomTransformers() {
return {
before: [
transform(),
],
};
},
},
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
sourceMap: mode === 'development',
},
},
{
loader: 'sass-loader',
options: {
sourceMap: mode === 'development',
},
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'static/[name].css',
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
],
devtool: mode === 'production' ? undefined : 'source-map',
devServer: {
static: path.join(rootDir, 'dist'),
compress: true,
port: 9526,
hot: true,
setupMiddlewares(middlewares, server) {
server.app.use('/api', api);
return middlewares;
},
},
};
}