This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
webpack.renderer.config.js
176 lines (172 loc) · 6.2 KB
/
webpack.renderer.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const webpack = require('webpack');
const merge = require('webpack-merge');
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const HappyPack = require('happypack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { build } = require('./package');
const baseConfig = require('./webpack.base.config');
const fixNedbForElectronRenderer = {
apply(resolver) {
resolver
// Plug in after the description file (package.json) has been
// identified for the import, which makes sure we're not getting
// mixed up with a different package.
.getHook('beforeDescribed-relative')
.tapAsync(
'FixNedbForElectronRenderer',
(request, resolveContext, callback) => {
// When a require/import matches the target files, we
// short-circuit the Webpack resolution process by calling the
// callback with the finalized request object -- meaning that
// the `path` is pointing at the file that should be imported.
const isNedbImport = request.descriptionFileData['name'] === 'nedb';
if (isNedbImport && /storage(\.js)?/.test(request.path)) {
const newRequest = Object.assign({}, request, {
path: resolver.join(
request.descriptionFileRoot,
'lib/storage.js'
)
});
callback(null, newRequest);
} else if (
isNedbImport &&
/customUtils(\.js)?/.test(request.path)
) {
const newRequest = Object.assign({}, request, {
path: resolver.join(
request.descriptionFileRoot,
'lib/customUtils.js'
)
});
callback(null, newRequest);
} else {
// Calling `callback` with no parameters proceeds with the
// normal resolution process.
return callback();
}
}
);
}
};
module.exports = merge.smart(baseConfig, {
target: 'electron-renderer',
entry: {
app: ['./src/renderer/app.tsx']
},
output: {
globalObject: 'this'
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: 'happypack/loader',
},
{
test: /\.scss$/,
loaders: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader']
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'babel-loader'
},
{
loader: '@svgr/webpack',
options: {
babel: true,
icon: true
}
}
]
},
{
test: /\.(gif|png|jpe?g)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
},
{
test: /\.(dat|mp3)$/,
use: 'file-loader'
},
{
test: /\.worker\.js$/,
use: { loader: 'index-loader' }
}
]
},
plugins: [
new HappyPack({
loaders: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
presets: [
[
'@babel/preset-env',
{
targets: { browsers: 'last 2 versions ' },
modules: false
}
],
'@babel/preset-typescript',
'@babel/preset-react'
],
plugins: [
'@babel/plugin-transform-runtime',
[
'@babel/plugin-proposal-class-properties',
{ loose: true }
]
]
}
}
]
}),
new ForkTsCheckerWebpackPlugin({
reportFiles: ['src/renderer/**/*']
}),
new CopyPlugin([
{ from: path.resolve(__dirname, 'public'), to: path.resolve(__dirname, 'dist') },
]),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
title: build.productName,
template: 'public/index.html',
inject: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
})
],
resolve: {
plugins: [
// This plugin allow us to use nedb of node.js version directly
// in renderer process (and the web index)
// See https://stackoverflow.com/questions/55389659/persist-nedb-to-disk-in-electron-renderer-process-webpack-electron-nedb-configu
fixNedbForElectronRenderer
]
}
});