-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathwebpack.config.js
More file actions
125 lines (121 loc) · 3.6 KB
/
webpack.config.js
File metadata and controls
125 lines (121 loc) · 3.6 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
const path = require('node:path');
const { execSync } = require('node:child_process');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
// Get git commit SHA at build time
const getGitCommitSha = () => {
try {
return execSync('git rev-parse --short HEAD').toString().trim();
} catch {
return 'unknown';
}
};
// First loaded always wins, so load .env first
if (process.env.NODE_ENV === 'development') {
require('dotenv').config({ path: '.env' });
}
// For production builds, also load .env.production
require('dotenv').config({ path: '.env.production' });
module.exports = {
entry: {
main: './src/index.ts',
'popup-callback': './src/user-account/popup-callback.ts'
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
publicPath: '/'
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@app': path.resolve(__dirname, 'src'),
'@engine': path.resolve(__dirname, 'src/engine'),
}
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|jpeg|gif|svg|otf|ttf|woff|woff2)$/,
type: 'asset/resource'
},
{
test: /\.(mp3|wav)$/,
type: 'asset/resource'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
chunks: ['main'],
filename: 'index.html'
// favicon: './public/favicon.ico'
}),
new HtmlWebpackPlugin({
template: './public/auth/callback.html',
chunks: ['popup-callback'],
filename: 'auth/callback.html'
}),
new webpack.DefinePlugin({
'process.env.PUBLIC_SUPABASE_URL': JSON.stringify(process.env.PUBLIC_SUPABASE_URL),
'process.env.PUBLIC_SUPABASE_ANON_KEY': JSON.stringify(process.env.PUBLIC_SUPABASE_ANON_KEY),
'process.env.PUBLIC_USER_API_URL': JSON.stringify(process.env.PUBLIC_USER_API_URL || 'https://user.keeptrack.space'),
'process.env.PUBLIC_ASSETS_BASE_URL': JSON.stringify(process.env.PUBLIC_ASSETS_BASE_URL || ''),
'process.env.PUBLIC_DEV_USER_IDS': JSON.stringify(process.env.PUBLIC_DEV_USER_IDS || ''),
'process.env.PUBLIC_LOG_LEVEL': JSON.stringify(process.env.PUBLIC_LOG_LEVEL || 'LOG'),
'__APP_VERSION__': JSON.stringify(require('./package.json').version),
'__GIT_COMMIT_SHA__': JSON.stringify(getGitCommitSha()),
}),
new CaseSensitivePathsPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: 'public/assets/logo.png', to: 'logo.png' },
{
from: 'public/assets/characters/',
to: 'assets/characters/',
globOptions: {
ignore: ['**/*.png', '**/wip/**']
}
},
{
from: 'public/images/',
to: 'images/',
globOptions: {
ignore: ['**/wip/**']
}
},
]
})
],
devServer: {
static: {
directory: path.join(__dirname, 'public')
},
compress: false,
port: 3000,
hot: true,
historyApiFallback: {
rewrites: [
// Don't redirect auth callback - serve the actual HTML file
{ from: /^\/auth\/callback/, to: '/auth/callback.html' },
// All other routes go to index.html
{ from: /./, to: '/index.html' }
]
},
liveReload: false
}
};