telegram-tt/webpack.config.js

144 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-04-09 12:29:59 +02:00
const path = require('path');
const dotenv = require('dotenv');
const { 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');
const TerserJSPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
2021-04-09 12:29:59 +02:00
dotenv.config();
module.exports = (env = {}, argv = {}) => {
return {
mode: argv.mode,
entry: './src/index.tsx',
target: 'web',
2021-04-09 12:29:59 +02:00
devServer: {
contentBase: [
path.resolve(__dirname, 'public'),
path.resolve(__dirname, 'node_modules/emoji-data-ios'),
path.resolve(__dirname, 'node_modules/opus-recorder/dist'),
path.resolve(__dirname, 'src/lib/webp'),
path.resolve(__dirname, 'src/lib/rlottie'),
],
port: 1234,
host: '0.0.0.0',
disableHostCheck: true,
stats: 'minimal',
},
output: {
filename: '[name].[contenthash].js',
chunkFilename: '[id].[chunkhash].js',
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+)?$/,
type: 'asset/resource',
2021-04-09 12:29:59 +02:00
},
{
test: /-extra\.json$/,
loader: 'file-loader',
type: 'javascript/auto',
options: {
name: '[name].[contenthash].[ext]',
},
},
{
test: /\.wasm$/,
loader: 'file-loader',
type: 'javascript/auto',
options: {
name: '[name].[contenthash].[ext]',
},
},
{
test: /\.tl$/i,
loader: 'raw-loader',
},
],
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
fallback: {
path: require.resolve("path-browserify"),
os: require.resolve("os-browserify/browser"),
buffer: require.resolve("buffer/"),
fs: false,
}
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({
2021-06-20 15:50:42 +02:00
APP_NAME: 'Telegram WebZ',
2021-06-12 03:40:17 +02:00
APP_VERSION: 'dev',
2021-04-09 12:29:59 +02:00
APP_ENV: 'production',
TELEGRAM_T_API_ID: '',
TELEGRAM_T_API_HASH: '',
2021-06-24 17:42:16 +02:00
TEST_SESSION: '',
2021-04-09 12:29:59 +02:00
}),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
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: [
new TerserJSPlugin({ sourceMap: true }),
new CssMinimizerPlugin(),
2021-04-09 12:29:59 +02:00
],
},
}),
};
};