forked from EdgeTTS/EdgeTTS.github.io
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
115 lines (104 loc) · 3.16 KB
/
Copy pathwebpack.config.js
File metadata and controls
115 lines (104 loc) · 3.16 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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default (_env, argv) => {
const isProduction = argv.mode === 'production';
return {
entry: './src/index.tsx',
output: {
path: isProduction
? path.resolve(__dirname, 'dist', 'latest')
: path.resolve(__dirname, 'dist'),
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
publicPath: isProduction ? './' : '/',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat',
'@': path.resolve(__dirname, 'src'),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, 'tsconfig.webpack.json'),
},
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'postcss-loader',
],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new CleanWebpackPlugin({
// Only clean the specific version subfolder, not entire dist
cleanOnceBeforeBuildPatterns: ['**/*'],
}),
new HtmlWebpackPlugin({
template: './public/index.html',
favicon: './public/logo.png',
}),
new MiniCssExtractPlugin({
filename: isProduction ? '[name].[contenthash].css' : '[name].css',
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'public/RU.lexx', to: 'RU.lexx' },
{ from: 'public/*.md', to: '[name][ext]' },
{ from: 'public/cors-diagram.png', to: 'cors-diagram.png' },
{ from: 'node_modules/@ffmpeg/core/dist/umd/ffmpeg-core.js', to: 'ffmpeg-core.js' },
{ from: 'node_modules/@ffmpeg/core/dist/umd/ffmpeg-core.wasm', to: 'ffmpeg-core.wasm' },
{ from: 'node_modules/onnxruntime-web/dist/*.wasm', to: '[name][ext]' },
...(isProduction ? [{ from: 'public/404.html', to: '../404.html' }] : []),
],
}),
],
devServer: {
static: './dist',
hot: true,
port: 3000,
open: true,
},
devtool: isProduction ? 'source-map' : 'eval-source-map',
// Suppress FFmpeg dynamic import warnings (expected behavior)
ignoreWarnings: [
{
module: /@ffmpeg[\\/]ffmpeg[\\/]dist[\\/]esm/,
message: /Critical dependency/,
},
],
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
};
};