-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
108 lines (102 loc) · 2.74 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
const lodash = require('lodash');
const CopyPkgJsonPlugin = require('copy-pkg-json-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
function srcPaths(src) {
return path.join(__dirname, src);
}
const isEnvProduction = process.env.NODE_ENV === 'production';
const isEnvDevelopment = process.env.NODE_ENV === 'development';
// #region Common settings
const commonConfig = {
devtool: isEnvDevelopment ? 'source-map' : false,
mode: isEnvProduction ? 'production' : 'development',
output: { path: srcPaths('dist') },
node: { __dirname: false, __filename: false },
resolve: {
alias: {
'@': srcPaths('src'),
'@main': srcPaths('src/main'),
'@models': srcPaths('src/models'),
'@public': srcPaths('public'),
'@renderer': srcPaths('src/renderer'),
'@utils': srcPaths('src/utils'),
},
extensions: ['.js', '.json', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: 'ts-loader',
},
{
test: /\.svg/,
use: {
loader: 'svg-inline-loader',
options: {}
}
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
include: srcPaths('public/fonts'),
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
},
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.(jpg|png|ico|icns)$/,
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
},
],
},
};
// #endregion
const mainConfig = lodash.cloneDeep(commonConfig);
mainConfig.entry = './src/main/main.ts';
mainConfig.target = 'electron-main';
mainConfig.output.filename = 'main.bundle.js';
mainConfig.plugins = [
new CopyPkgJsonPlugin({
remove: ['scripts', 'devDependencies', 'build'],
replace: {
main: './main.bundle.js',
scripts: { start: 'electron ./main.bundle.js' },
postinstall: 'electron-builder install-app-deps',
},
}),
];
const rendererConfig = lodash.cloneDeep(commonConfig);
rendererConfig.entry = './src/renderer/renderer.tsx';
rendererConfig.target = 'electron-renderer';
rendererConfig.output.filename = 'renderer.bundle.js';
rendererConfig.plugins = [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './public/index.html'),
}),
new CopyPlugin({
patterns: [
{
from: './public/fonts/fabric-icons-*',
to: 'fonts',
flatten: true,
},
],
}),
];
module.exports = [mainConfig, rendererConfig];