This repository has been archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
79 lines (75 loc) · 1.86 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
require('dotenv').config();
const distPath = path.join(__dirname, 'dist');
let examples = ['index', 'matchmaker', 'native'];
module.exports = {
mode: 'development',
entry: Object.fromEntries([
...examples.map(name => [`${name}-js`, path.resolve(__dirname, 'src', 'examples', `${name}.ts`)]),
...examples.map(name => [
`${name}-css`,
path.resolve(__dirname, 'src', 'styles', `${name}-html.scss`)
])
]),
output: {
filename: '[name].[contenthash].bundle.js',
path: distPath
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.s[ac]ss$/i,
issuer: /\.tsx?$/,
use: ['css-loader', 'sass-loader']
},
{
test: /\.s[ac]ss$/i,
issuer: /^(?:(?!\.tsx?).)*$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
type: 'asset/resource'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
plugins: [
...(process.env.PROD == '1'
? [new Dotenv({ path: '.env.prod' })]
: [new Dotenv({ path: '.env' }), new Dotenv({ path: '.env.dev' })]),
new webpack.EnvironmentPlugin({
RIVET_API_ENDPOINT: process.env.RIVET_API_ENDPOINT ?? 'https://api.rivet.gg'
}),
new MiniCssExtractPlugin(),
...examples.map(name => {
return new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'html', `${name}.html`),
filename: path.join(distPath, `${name}.html`),
chunks: [`${name}-js`, `${name}-css`]
});
})
],
devServer: {
compress: true,
port: 5000,
allowedHosts: 'all',
host: '0.0.0.0'
},
optimization: {
splitChunks: {
chunks: 'all'
}
}
};