-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (104 loc) · 3.78 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
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const createElectronReloadWebpackPlugin = require('electron-reload-webpack-plugin');
const buildPath = 'build'; //build path
const ElectronReloadWebpackPlugin = createElectronReloadWebpackPlugin({
// Path to `package.json` file with main field set to main process file path, or just main process file path
path: path.join(__dirname, buildPath, './main.js'),
// or just `path: './'`,
// Other 'electron-connect' options
logLevel: 0
});
const IMAGE_TYPES = /\.(png|jpe?g|gif|svg)$/i;
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
return [
{
entry: {
main: './src/main.js', // Entry point for the main process
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, buildPath),
},
target: 'electron-main',
stats: {
all: false,
errors: true,
builtAt: true,
assets: true,
excludeAssets: [IMAGE_TYPES],
},
node: {
__dirname: false,
__filename: false,
},
// Additional configuration options for loaders, plugins, etc. can be added here
plugins: [
!isProduction && ElectronReloadWebpackPlugin(), // hot reaload
].filter(Boolean),
},
{
entry: {
renderer: './src/renderer.js', // Entry point for the renderer process
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, buildPath),
publicPath: './',
assetModuleFilename: 'images/[hash][ext][query]'
},
target: 'electron-renderer',
stats: {
all: false,
errors: true,
builtAt: true,
assets: true,
excludeAssets: [IMAGE_TYPES],
},
module: {
rules: [
// Help webpack in understanding CSS files imported in .js files
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
// html loader
{
test: /\.html$/i,
loader: "html-loader",
},
// asset loader
{
test: IMAGE_TYPES,
type: 'asset/resource'
}
],
},
// Additional configuration options for loaders, plugins, etc. can be added here
plugins: [
!isProduction && ElectronReloadWebpackPlugin('electron-renderer'), // hot reaload
// Copy static assets from `public` folder to `build` folder
new CopyWebpackPlugin({
patterns: [{
from: '*',
context: 'public',
}],
}),
// Extract CSS into separate files
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new webpack.ExternalsPlugin('commonjs', [
'electron'
]),
new HtmlWebpackPlugin({
template: "./src/index.html"
}),
].filter(Boolean)
}
]
}