This commit is contained in:
Andrey Sharshov
2025-11-16 18:48:06 +01:00
commit c02d04073f
481 changed files with 52066 additions and 0 deletions

119
bundler/webpack.common.js Normal file
View File

@@ -0,0 +1,119 @@
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = (env) => {
// Корневая директория проекта
const rootDir = path.resolve(__dirname, '../');
return {
context: path.resolve(process.cwd()), // Корень проекта
entry: './src/index.js', // Относительный путь от контекста
output: {
hashFunction: 'xxhash64',
filename: 'bundle.js',
path: path.resolve(process.cwd(), 'dist')
},
resolve: {
extensions: ['.js', '.ts'],
symlinks: true, // Включает поддержку символических ссылок
alias: {
services: path.resolve(process.cwd(), 'services'),
utils: path.resolve(process.cwd(), 'utils'),
extensions: path.resolve(process.cwd(), 'extensions'),
decorators: path.resolve(process.cwd(), 'decorators'),
base: path.resolve(process.cwd(), 'base')
},
modules: [
path.resolve(rootDir), // Убедитесь, что пути абсолютные
'node_modules',
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(process.cwd(), 'src/assets') },
{ from: path.resolve(process.cwd(), 'public/imgs') },
{ from: path.resolve(__dirname, '../assets')},
],
}),
new HtmlWebpackPlugin({
template: path.resolve(process.cwd(), 'public/index.html'),
minify: true
}),
new MiniCSSExtractPlugin(),
new webpack.DefinePlugin({
__VERSION: JSON.stringify(require(path.resolve(process.cwd(), 'package.json')).version),
__STORAGE_ID: JSON.stringify(require(path.resolve(process.cwd(), 'package.json')).storageId),
}),
],
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
// JS
{
test: /\.js$|\.jsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/env', '@babel/react'],
},
},
},
// Images
{
test: /\.(jpg|png|webp|gif|svg|mp3)$/,
type: 'asset/resource',
generator: {
filename: 'assets/images/[hash][ext]',
},
},
// Sounds
{
test: /\.(mp3|ogg)$/,
type: 'asset/resource',
generator: {
filename: 'assets/sounds/[hash][ext]',
},
},
// Fonts
{
test: /\.(ttf|eot|woff|woff2|otf)$/,
type: 'asset/resource',
generator: {
filename: 'assets/fonts/[hash][ext]',
},
},
],
},
optimization: {
splitChunks: {
chunks: 'async',
minSize: 20000,
minRemainingSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
};
};

72
bundler/webpack.dev.js Normal file
View File

@@ -0,0 +1,72 @@
const path = require('path');
const { merge } = require('webpack-merge');
const commonConfiguration = require('./webpack.common.js');
const ip = require('ip');
const portFinderSync = require('portfinder-sync');
const fs = require("fs");
const infoColor = (_message) => {
return `\u001b[1m\u001b[34m${_message}\u001b[39m\u001b[22m`;
};
module.exports = (env) => {
return merge(
commonConfiguration(env),
{
devtool: 'source-map',
stats: 'errors-warnings',
mode: 'development',
infrastructureLogging:
{
level: 'warn',
},
snapshot: { managedPaths: [] },
devServer:
{
// host: 'local-ip',
port: portFinderSync.getPort(3000),
open: true,
https: false,
allowedHosts: 'all',
hot: false,
//watchFiles: ['./',],
client:
{
logging: 'none',
overlay: true,
progress: false,
},
setupMiddlewares: function (middlewares, devServer) {
const port = devServer.options.port;
const https = devServer.options.https ? 's' : '';
const localIp = ip.address();
const domain1 = `http${https}://${localIp}:${port}`;
const domain2 = `http${https}://localhost:${port}`;
console.log(`Project running at:\n - ${infoColor(domain1)}\n - ${infoColor(domain2)}`);
return middlewares;
},
proxy: { // used to be able to send cookies via fetch
"/proxy": {
target: "https://dev.popiplay.dev",
changeOrigin: true,
secure: false,
pathRewrite: { "^/proxy": "" }, // removes "/proxy" before redirection
cookieDomainRewrite: "localhost",
// dynamic replace
router: (req) => {
const cookieHeader = req.headers.cookie || "";
const match = cookieHeader.match(/proxy_target=([^;]+)/);
const target = match ? ("https://" + decodeURIComponent(match[1])) : "https://dev.popiplay.dev";
// console.error(`[proxy][router] ${req.method} ${req.url} -> ${target}`);
// console.error(`[proxy][router] ${target}`);
return target;
},
},
},
},
},
);
}

46
bundler/webpack.prod.js Normal file
View File

@@ -0,0 +1,46 @@
const {merge} = require('webpack-merge');
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
const commonConfiguration = require('./webpack.common.js');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const webpack = require('webpack')
// available CI variables https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
const SENTRY_DSN = process.env.SENTRY_DSN;
const version = require(path.resolve(process.cwd(), 'package.json')).version;
const SENTRY_RELEASE = `${process.env.CI_PROJECT_NAME} ${version}`;
const AMPLITUDE_API_KEY = process.env.AMPLITUDE_API_KEY_PROD
module.exports = (env) => {
return merge(
commonConfiguration(env),
{
context: path.resolve(process.cwd()), // Корень проекта
entry: './src/prod.js', // Относительный путь от контекста
mode: 'production',
devtool: 'source-map',
plugins:
[
new webpack.DefinePlugin({
__SENTRY_DSN: JSON.stringify(SENTRY_DSN),
__SENTRY_RELEASE: JSON.stringify(SENTRY_RELEASE),
__AMPLITUDE_API_KEY: JSON.stringify(AMPLITUDE_API_KEY),
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, '../loader/loader.js') },
],
}),
sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: "sentry",
project: process.env.SENTRY_PROJECT,
url: "https://sentry.popiplay.dev",
}),
],
},
);
}

View File

@@ -0,0 +1,46 @@
const {merge} = require('webpack-merge');
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
const commonConfiguration = require('./webpack.common.js');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const webpack = require('webpack')
// available CI variables https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
const SENTRY_DSN = process.env.SENTRY_DSN_DEV;
const version = require(path.resolve(process.cwd(), 'package.json')).version;
const SENTRY_RELEASE = `${process.env.CI_PROJECT_NAME} ${version}`;
const AMPLITUDE_API_KEY = process.env.AMPLITUDE_API_KEY_TEST
module.exports = (env) => {
return merge(
commonConfiguration(env),
{
context: path.resolve(process.cwd()), // Корень проекта
entry: './src/staging.js', // Относительный путь от контекста
mode: 'production',
devtool: 'source-map',
plugins:
[
new webpack.DefinePlugin({
__SENTRY_DSN: JSON.stringify(SENTRY_DSN),
__SENTRY_RELEASE: JSON.stringify(SENTRY_RELEASE),
__AMPLITUDE_API_KEY: JSON.stringify(AMPLITUDE_API_KEY),
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, '../loader/loader.js') },
],
}),
sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: "sentry",
project: process.env.SENTRY_PROJECT,
url: "https://sentry.popiplay.dev",
}),
],
},
);
}