This repository has been archived by the owner on Jan 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
105 lines (100 loc) · 2.62 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
require('dotenv').config({ silent: true });
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { spawn } = require('child_process');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const config = {
mode: isProduction ? 'production' : 'development',
target: 'electron-renderer',
entry: {
app: path.resolve(__dirname, 'render/'),
about: path.resolve(__dirname, 'render/about')
},
output: {
path: path.resolve(__dirname, './dist'),
// to avoid extra slash at the beginning, that makes the file:// request result in a RESOURCE_NOT_FOUND error
publicPath: isProduction ? '' : '/',
filename: '[name].js'
},
module: {
rules: [
{
test: /\.[tj]sx?$/,
use: 'ts-loader'
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.txt$/,
use: [
'raw-loader'
]
}
]
},
externals: [nodeExternals({
allowlist: [/\.(?!(?:jsx?|json)$).{1,5}$/i]
})],
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.css']
},
stats: {
colors: true,
children: false,
chunks: false,
modules: false
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css'
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, './render/index.html'),
chunks: ['app']
}),
new HtmlWebpackPlugin({
filename: 'about.html',
template: path.resolve(__dirname, './render/about/about.html'),
chunks: ['about']
})
]
};
if (!isProduction) {
config.devServer = {
static: {
directory: path.resolve(__dirname, './dist'),
publicPath: '/',
watch: true,
},
client: {
overlay: false,
},
hot: true,
liveReload: true,
port: process.env.PORT,
onBeforeSetupMiddleware: () => spawn('electron', ['.'], { shell: true, env: process.env, stdio: 'inherit' })
.once('close', () => process.exit(0))
// eslint-disable-next-line
.once('error', (spawnError) => console.error(spawnError))
};
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
module.exports = config;