forked from wexond/browser-base
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.renderers.js
132 lines (123 loc) · 3.65 KB
/
webpack.renderers.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
/* eslint-disable */
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const path = require('path')
const {
webpackModule,
getOptimization,
output,
resolve,
Mode,
} = require('./webpack/utils')
function reactAppConfig(name, mainEntryPath, extraEntries) {
const filename = `${name}.html`
const entry = {
[name]: mainEntryPath,
...extraEntries,
}
const plugins = [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, `static/pages/${filename}`),
filename,
chunks: [name],
}),
]
return { entry, filename, plugins }
}
function appConfig(name, fileType, packageJSON) {
const entry = {
[name]: {
import: `./src/applications/${name}/views/index.${fileType}`,
filename: `${name}/[name].js`,
},
[`${name}-preload`]: {
import: `./src/applications/${name}/preload.ts`,
filename: `${name}/preload.js`,
},
}
const plugins = [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, `./src/applications/${name}/views/index.html`),
filename: `${name}/index.html`,
chunks: [name]
}),
]
if (packageJSON) {
plugins.push(new CopyWebpackPlugin({
patterns: [
{
from: `./src/applications/${name}/package.json`,
to: `${name}/package.json`,
},
]
}))
}
return { entry, plugins }
}
module.exports = (env) => {
const mode = env?.production ? Mode.PRODUCTION : Mode.DEVELOPMENT
const optimization = getOptimization(mode)
const {
entry: appEntry,
plugins: appPlugins,
filename: appFilename,
} = reactAppConfig('app', './src/wexond/renderer/app/index.tsx', {
'view-preload': './src/wexond/preloads/view-preload.ts',
})
const {
entry: configEntry,
plugins: configPlugins,
filename: configFilename,
} = reactAppConfig('config', './src/config/index.tsx', { 'config-preload': './src/config/preload.ts' })
const baseEntry = {
exportNode: './src/frontend/preloads/exportNode.ts',
'inactivity-preload': './src/inactivity/preload.ts',
...appEntry,
...configEntry,
}
const fileNamesToFilter = [appFilename, configFilename]
const basePlugins = [
...appPlugins,
...configPlugins,
new CopyWebpackPlugin({
patterns: [
{
from: './static/pages',
filter: (path) => {
// We must not emit app.html that is handled by the HtmlWebpackPlugin above
// ... otherwise an error is thrown
return !fileNamesToFilter.some(name => path.endsWith(name))
}
},
]
})
]
const flowrPhoneConfig = appConfig('FlowrPhone', 'tsx', true)
const keyboardConfig = appConfig('keyboard', 'ts')
return {
output,
target: 'electron-renderer',
resolve,
devtool: false,
mode,
optimization,
module: webpackModule,
externals: {
fs: 'commonjs fs',
path: 'commonjs path',
os: 'commonjs os',
process: 'commonjs process',
electron: 'commonjs electron',
},
entry: {
...baseEntry,
...flowrPhoneConfig.entry,
...keyboardConfig.entry,
},
plugins: [
...basePlugins,
...flowrPhoneConfig.plugins,
...keyboardConfig.plugins,
],
}
}