-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.renderer.dev.ts
160 lines (144 loc) · 4.13 KB
/
webpack.config.renderer.dev.ts
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
/**
* Build config for development electron renderer process that uses
* Hot-Module-Replacement
*
* https://webpack.js.org/concepts/hot-module-replacement/
*/
import HtmlWebpackPlugin from 'html-webpack-plugin';
import * as path from 'path';
import { Configuration, DefinePlugin, HotModuleReplacementPlugin } from 'webpack';
import { mergeWithRules, CustomizeRule } from 'webpack-merge';
import { spawn } from 'child_process';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import ReactRefreshPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import baseConfig from './webpack.config.base';
import CheckNodeEnv from './internals/scripts/CheckNodeEnv';
CheckNodeEnv('development');
const port = Number.parseInt(process.env.PORT || '1212', 10);
const rendererDevConfig: Configuration = {
mode: 'development',
devtool: 'eval-cheap-module-source-map',
target: 'electron-renderer',
entry: { renderer: path.join(__dirname, 'app/index.tsx') },
output: {
path: path.join(__dirname, 'build', 'dist'),
filename: '[name].dev.js'
},
externals: ['fsevents', 'crypto-browserify', '../build/Debug/nodegit.node'],
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react', '@babel/typescript'],
plugins: ['@babel/proposal-class-properties', 'react-refresh/babel'],
cacheDirectory: path.join(__dirname, '.yarn/.cache/babel-loader'),
cacheCompression: false
}
}
},
{
test: /\.node$/,
use: 'node-loader'
},
// Extract all .global.css to style.css as is, pipe other styles through css modules and append to style.css
{
test: /\.s?css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: {
auto: /^((?!\.global).)*\.s?css$/,
localIdentName: '[name]__[local]__[hash:base64:5]',
exportLocalsConvention: 'camelCase'
}
}
},
{
loader: 'sass-loader'
}
]
}
]
},
plugins: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
new HotModuleReplacementPlugin(),
new ReactRefreshPlugin() as any,
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'app/app.html')
})
],
optimization: {
emitOnErrors: false,
runtimeChunk: true,
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: {
chunks: 'all',
cacheGroups: {
defaultVendors: {
test: /[\\/].yarn[\\/]/,
priority: -10,
reuseExistingChunk: true
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
},
node: {
__dirname: false,
__filename: false
},
watchOptions: {
aggregateTimeout: 300,
ignored: /\.yarn|\.git/,
poll: 100
},
stats: 'errors-only',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
devServer: {
port,
compress: true,
headers: { 'Access-Control-Allow-Origin': '*' },
onBeforeSetupMiddleware() {
if (process.env.START_HOT) {
console.log('Staring Main Process...');
spawn('yarn', ['run', 'start-main-dev', '--', process.env.MAIN_ARGS || ''], {
shell: true,
env: { ...process.env, DEV_SERVER_ROOT: 'http://localhost:1212/' },
stdio: 'inherit'
})
.on('close', (code) => process.exit(code || undefined))
.on('error', (spawnError) => console.error(spawnError));
}
}
} as any,
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename] // you may omit this when your CLI automatically adds it
}
}
};
export default mergeWithRules({
module: {
rules: {
test: CustomizeRule.Match,
use: CustomizeRule.Replace
}
}
})(baseConfig, rendererDevConfig);