forked from ruslang02/discord-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
129 lines (128 loc) · 3.35 KB
/
webpack.config.js
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
const path = require('path');
const fs = require('fs');
const childProcess = require('child_process');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { DefinePlugin } = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const globImporter = require('node-sass-glob-importer');
const { readdirSync } = fs;
let __BUILDNUM__;
try {
__BUILDNUM__ = childProcess.execSync('git rev-list HEAD --count').toString()
} catch (e) {
__BUILDNUM__ = 0;
}
module.exports = (_env, argv) => {
const isDev = argv.mode !== 'production';
const themes = Object.fromEntries(readdirSync('./src/themes').map(value => [
value.replace('.scss', ''),
'./src/themes/' + value
]));
return {
mode: isDev ? 'development' : 'production',
entry: {
'index.js': './src',
'worker.js': './worker',
...themes
},
optimization: {
minimize: !isDev,
minimizer: [new TerserPlugin({
terserOptions: {
keep_classnames: true
}
})],
},
target: 'node',
node: {
__dirname: false,
__filename: false,
fs: 'empty',
},
output: {
filename: '[name]',
path: path.resolve(__dirname, 'dist'),
pathinfo: false,
},
module: {
exprContextCritical: false,
rules: [
{
test: /\.tsx?$/,
exclude: /discord-qt\/node_modules/g,
use: [
'thread-loader',
{
loader: 'ts-loader',
options: {
transpileOnly: true,
happyPackMode: true,
experimentalWatchApi: true,
}
}
]
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: { publicPath: 'dist' },
},
],
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
importer: globImporter(),
}
}
},
],
},
{
test: /\.node$/,
use: [
{
loader: 'native-addon-loader',
options: { name: '[name].[ext]' },
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx', '.json', '.wasm'],
mainFields: ['main'],
alias: {
'fetch': path.join(__dirname, '../node_modules', 'whatwg-fetch', 'fetch.js'),
}
},
plugins: [
new CleanWebpackPlugin(),
new DefinePlugin({ __BUILDNUM__ }),
new MiniCssExtractPlugin({
filename: 'themes/[name].css',
}),
new CopyPlugin({
patterns: [
{ from: 'assets', to: 'assets' },
{ from: 'locales', to: 'locales' },
{ from: 'node_modules/opusscript/build/opusscript_native_wasm.wasm' },
{ from: 'node_modules/ffmpeg-static/ffmpeg', noErrorOnMissing: true },
{ from: 'node_modules/ffmpeg-static/ffmpeg.exe', noErrorOnMissing: true }
]
})
],
}
};