-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
86 lines (77 loc) · 2.04 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
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const sourcePath = path.resolve(__dirname, 'src');
const buildPath = path.resolve(__dirname, 'build');
const IS_PROD = process.env.NODE_ENV === 'production';
const pathsToClean = [
path.resolve(buildPath, 'main'),
path.resolve(buildPath, 'renderer')
];
const commonConfig = {
output: {
path: buildPath,
filename: '[name].js'
},
// Disable mocking node globals
node: false,
devtool: IS_PROD ? false : 'source-map',
mode: IS_PROD ? 'production' : 'development'
};
module.exports = [
{
target: 'electron-main',
entry: {
'main/main': path.resolve(sourcePath, 'main/main.js')
},
...commonConfig
}, {
target: 'electron-renderer',
entry: {
'renderer/renderer': path.resolve(sourcePath, 'renderer/renderer.js')
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: !IS_PROD
}
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(pathsToClean, {
verbose: true
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new HtmlWebpackPlugin({
template: path.resolve(sourcePath, 'renderer/index.html'),
filename: path.resolve(buildPath, 'renderer/index.html')
}),
new CopyWebpackPlugin([
{
from: path.resolve(sourcePath, 'renderer/img/*.png'),
to: path.resolve(buildPath, 'renderer/img/'),
flatten: true,
transform(content) {
// TODO: Maybe optimize images here
return content;
}
}
])
],
...commonConfig
}
];