2021-04-09 12:29:59 +02:00
|
|
|
const path = require('path');
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
|
2021-10-22 12:49:20 +02:00
|
|
|
const {
|
2022-02-25 21:52:41 +01:00
|
|
|
DefinePlugin,
|
2021-10-22 12:49:20 +02:00
|
|
|
EnvironmentPlugin,
|
|
|
|
ProvidePlugin,
|
|
|
|
} = require('webpack');
|
2021-04-09 12:29:59 +02:00
|
|
|
const HtmlPlugin = require('html-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2021-10-22 12:49:20 +02:00
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
2022-02-20 12:39:30 +01:00
|
|
|
const { GitRevisionPlugin } = require('git-revision-webpack-plugin');
|
|
|
|
|
2022-02-25 21:52:32 +01:00
|
|
|
const appVersion = require('./package.json').version;
|
2021-04-09 12:29:59 +02:00
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
module.exports = (env = {}, argv = {}) => {
|
|
|
|
return {
|
|
|
|
mode: argv.mode,
|
|
|
|
entry: './src/index.tsx',
|
2021-08-16 13:21:20 +02:00
|
|
|
target: 'web',
|
2021-04-09 12:29:59 +02:00
|
|
|
devServer: {
|
|
|
|
port: 1234,
|
|
|
|
host: '0.0.0.0',
|
2022-02-02 22:48:08 +01:00
|
|
|
allowedHosts: "all",
|
2022-02-02 22:49:44 +01:00
|
|
|
hot: false,
|
2022-02-02 22:48:08 +01:00
|
|
|
static: [
|
|
|
|
{
|
|
|
|
directory: path.resolve(__dirname, 'public'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
directory: path.resolve(__dirname, 'node_modules/emoji-data-ios'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
directory: path.resolve(__dirname, 'node_modules/opus-recorder/dist'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
directory: path.resolve(__dirname, 'src/lib/webp'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
directory: path.resolve(__dirname, 'src/lib/rlottie'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
directory: path.resolve(__dirname, 'src/lib/secret-sauce'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
devMiddleware: {
|
|
|
|
stats: 'minimal',
|
|
|
|
},
|
2021-04-09 12:29:59 +02:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].[contenthash].js',
|
|
|
|
chunkFilename: '[id].[chunkhash].js',
|
2021-08-16 13:21:20 +02:00
|
|
|
assetModuleFilename: '[name].[contenthash].[ext]',
|
2021-04-09 12:29:59 +02:00
|
|
|
path: path.resolve(__dirname, argv['output-path'] || 'dist'),
|
|
|
|
},
|
|
|
|
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: /\.scss$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader',
|
|
|
|
'sass-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff(2)?|ttf|eot|svg|png|jpg|tgs)(\?v=\d+\.\d+\.\d+)?$/,
|
2021-08-16 13:21:20 +02:00
|
|
|
type: 'asset/resource',
|
2021-04-09 12:29:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.wasm$/,
|
2022-02-11 15:13:05 +01:00
|
|
|
type: 'asset/resource',
|
2021-04-09 12:29:59 +02:00
|
|
|
},
|
|
|
|
{
|
2021-10-22 12:49:20 +02:00
|
|
|
test: /\.(txt|tl)$/i,
|
2022-02-11 15:13:05 +01:00
|
|
|
type: 'asset/source',
|
2021-04-09 12:29:59 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.ts', '.tsx'],
|
2021-08-16 13:21:20 +02:00
|
|
|
fallback: {
|
2021-10-22 12:49:20 +02:00
|
|
|
path: require.resolve('path-browserify'),
|
|
|
|
os: require.resolve('os-browserify/browser'),
|
|
|
|
buffer: require.resolve('buffer/'),
|
2021-08-16 13:21:20 +02:00
|
|
|
fs: false,
|
2021-10-22 12:49:20 +02:00
|
|
|
},
|
2021-04-09 12:29:59 +02:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HtmlPlugin({
|
|
|
|
template: 'src/index.html',
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: '[name].[contenthash].css',
|
|
|
|
chunkFilename: '[name].[chunkhash].css',
|
|
|
|
ignoreOrder: true,
|
|
|
|
}),
|
|
|
|
new EnvironmentPlugin({
|
|
|
|
APP_ENV: 'production',
|
2022-02-20 13:05:25 +01:00
|
|
|
APP_NAME: null,
|
2022-02-25 21:52:32 +01:00
|
|
|
APP_VERSION: appVersion,
|
2022-02-20 12:39:30 +01:00
|
|
|
TELEGRAM_T_API_ID: undefined,
|
|
|
|
TELEGRAM_T_API_HASH: undefined,
|
|
|
|
TEST_SESSION: null,
|
2021-04-09 12:29:59 +02:00
|
|
|
}),
|
2022-02-25 21:52:41 +01:00
|
|
|
new DefinePlugin({
|
|
|
|
APP_REVISION: DefinePlugin.runtimeValue(() => {
|
|
|
|
const { branch, commit } = getGitMetadata();
|
|
|
|
return JSON.stringify((!branch || branch === 'HEAD') ? commit : branch);
|
|
|
|
}, argv.mode === 'development' ? true : []),
|
|
|
|
}),
|
2021-08-16 13:21:20 +02:00
|
|
|
new ProvidePlugin({
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
2022-04-01 20:43:24 +02:00
|
|
|
process: 'process/browser',
|
2021-08-16 13:21:20 +02:00
|
|
|
}),
|
2021-04-09 12:29:59 +02:00
|
|
|
...(argv.mode === 'production' ? [
|
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
analyzerMode: 'static',
|
|
|
|
openAnalyzer: false,
|
|
|
|
}),
|
|
|
|
] : []),
|
|
|
|
],
|
|
|
|
|
|
|
|
...(!env.noSourceMap && {
|
|
|
|
devtool: 'source-map',
|
|
|
|
}),
|
|
|
|
|
|
|
|
...(argv['optimize-minimize'] && {
|
|
|
|
optimization: {
|
|
|
|
minimize: !env.noMinify,
|
|
|
|
minimizer: [
|
2021-08-16 13:21:20 +02:00
|
|
|
new CssMinimizerPlugin(),
|
2021-04-09 12:29:59 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
};
|
2022-02-25 21:52:41 +01:00
|
|
|
|
|
|
|
function getGitMetadata() {
|
|
|
|
const gitRevisionPlugin = new GitRevisionPlugin();
|
|
|
|
const branch = process.env.HEAD || gitRevisionPlugin.branch();
|
|
|
|
const commit = gitRevisionPlugin.commithash().substring(0, 7);
|
|
|
|
return { branch, commit };
|
|
|
|
}
|