forked from mytonwalletorg/mytonwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-giveaways.config.ts
187 lines (176 loc) · 4.95 KB
/
webpack-giveaways.config.ts
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import dotenv from 'dotenv';
import HtmlPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import path from 'path';
import type { Configuration } from 'webpack';
import {
EnvironmentPlugin, NormalModuleReplacementPlugin, ProvidePlugin,
} from 'webpack';
dotenv.config();
const { APP_ENV = 'production', GIVEAWAYS_API_URL = 'http://0.0.0.0:5005/' } = process.env;
const cspConnectSrcExtra = APP_ENV === 'development'
? `http://localhost:5005 ${GIVEAWAYS_API_URL}`
: GIVEAWAYS_API_URL;
const CSP = `
default-src 'none';
connect-src 'self' https: ${cspConnectSrcExtra};
script-src 'self' 'wasm-unsafe-eval' https://challenges.cloudflare.com/;
style-src 'self' https://fonts.googleapis.com/;
img-src 'self' data: https:;
media-src 'self' data:;
object-src 'none';
base-uri 'none';
font-src 'self' https://fonts.gstatic.com/;
form-action 'none';
frame-src 'self' https://challenges.cloudflare.com/`
.replace(/\s+/g, ' ').trim();
export default function createConfig(
_: any,
{ mode = 'production' }: { mode: 'none' | 'development' | 'production' },
): Configuration {
return {
mode,
entry: {
main: './src/giveaways/index.tsx',
},
devServer: {
port: 4322,
host: '0.0.0.0',
allowedHosts: 'all',
static: [
{
directory: path.resolve(__dirname, 'public'),
},
{
directory: path.resolve(__dirname, 'src/lib/rlottie'),
},
],
devMiddleware: {
stats: 'minimal',
},
headers: {
'Content-Security-Policy': CSP,
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
},
ignoreWarnings: [
(warning) => {
return /(config)|(windowEnvironment)/.test(warning.message);
},
],
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist-giveaways'),
clean: true,
},
module: {
rules: [
{
test: /\.(ts|tsx|js)$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
'postcss-loader',
],
},
{
test: /\.module\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
exportLocalsConvention: 'camelCase',
auto: true,
localIdentName: APP_ENV === 'production' ? '[sha1:hash:base64:8]' : '[name]__[local]',
},
},
},
'postcss-loader',
'sass-loader',
],
},
{
test: /\.scss$/,
exclude: /\.module\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.(woff(2)?|ttf|eot|svg|png|jpg|tgs|webp|mp3)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
},
{
test: /\.wasm$/,
type: 'asset/resource',
},
{
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
],
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
fallback: {
stream: require.resolve('stream-browserify'),
process: require.resolve('process/browser'),
},
},
plugins: [
new HtmlPlugin({
template: 'src/giveaways/index.html',
chunks: ['main'],
csp: CSP,
templateParameters: {
'process.env.BASE_URL': process.env.BASE_URL,
},
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[name].[chunkhash].css',
ignoreOrder: true,
}),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new ProvidePlugin({
process: 'process/browser',
}),
/* eslint-disable no-null/no-null */
new EnvironmentPlugin({
APP_ENV: 'production',
GIVEAWAYS_API_URL: null,
GIVEAWAY_CAPTCHA_PUBLIC_KEY: null,
}),
/* eslint-enable no-null/no-null */
new NormalModuleReplacementPlugin(
/src\/config\.ts/,
'./giveaways/config.ts',
),
new NormalModuleReplacementPlugin(
/src\/util\/windowEnvironment\.ts/,
'../giveaways/utils/windowEnvironment.ts',
),
new NormalModuleReplacementPlugin(
/i18n\/en\.json/,
'../giveaways/assets/mockI18N.json',
),
],
devtool: APP_ENV === 'development' ? 'source-map' : 'hidden-source-map',
};
}