-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
162 lines (159 loc) · 5.05 KB
/
Copy pathwebpack.config.ts
File metadata and controls
162 lines (159 loc) · 5.05 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import BeastiesPlugin from 'beasties-webpack-plugin';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import UnoCSSPlugin from '@unocss/webpack';
import { execSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import type { Configuration as Config } from 'webpack';
import { resolve } from 'node:path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
import fg from 'fast-glob';
import BrotliWasmWebpackPlugin from './brotliWasmWebpackPlugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import 'dotenv-flow/config';
const tsconfigRaw = JSON.parse(readFileSync('./tsconfig.json', 'utf-8'));
export default {
entry: fg.sync(['./src/index.tsx', './src/models/**']),
output: {
path: resolve(__dirname, 'dist'),
filename: '[name].js',
sourceMapFilename: '[name].js.map',
publicPath: '/',
},
resolve: {
plugins: [
new TsconfigPathsPlugin({ configFile: './tsconfig.json' })
],
extensions: [
'.ts',
'.tsx',
'.js',
'.jsx',
'.json',
'.bin',
'.gltf',
'.txt',
'.png',
'.webp',
],
},
plugins: [
new BeastiesPlugin(),
UnoCSSPlugin({
configFile: './unocss.config.ts',
}),
new HtmlWebpackPlugin({
filename: 'index.html',
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Eaglercraft Client Collections</title>
</head>
<body
class="bg-ctp-base text-ctp-text min-h-screen"
data-commit-hash="__COMMIT_HASH__"
data-zip-url="__ZIP_FILE_URL__"
>
<div id="root"></div>
</body>
</html>
`,
}),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new ReplaceInFileWebpackPlugin([
{
dir: 'dist',
files: ['index.html'],
rules: [
{
search: '__COMMIT_HASH__',
replace: (() => {
try {
return execSync('git rev-parse HEAD').toString().trim();
} catch (error) {
return 'unknown';
}
})(),
},
{
search: '__ZIP_FILE_URL__',
replace: (() => {
if (process.env.ZIP_FILE_URL) return process.env.ZIP_FILE_URL;
else return '/files.zip';
})(),
},
],
},
]),
new BrotliWasmWebpackPlugin({
test: /\.(js|css|html|svg)$/,
threshold: 1024,
quality: 9,
//addContentEncodingHeader: true
}),
(function() {
if (!process.env.ZIP_FILE_URL)
return new CopyWebpackPlugin({
patterns: [
{ from: 'public', to: '.' },
],
});
else return undefined;
})(),
],
module: {
rules: [
{
test: /\.(tsx|ts)$/,
use: [
{
loader: 'esbuild-loader',
options: {
tsconfigRaw,
},
},
],
},
{
test: /\.(png|webp|gltf|txt|bin)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
outputPath: (resourcePath: string, _: any) => {
return resourcePath.replace(/^src\//, 'assets/');
},
publicPath: '/assets/',
context: 'src/',
},
},
],
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
},
],
},
],
},
optimization: {
realContentHash: true,
},
} as Config;