Skip to content

Commit 8b30019

Browse files
authored
build: generate es module build for electron main (#2985)
1 parent d249c3f commit 8b30019

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

packages/uhk-agent/src/electron-main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ async function createWindow() {
104104
webPreferences: {
105105
contextIsolation: false,
106106
spellcheck: false,
107-
preload: path.join(__dirname, 'preload.js')
107+
preload: path.join(import.meta.dirname, 'preload.js')
108108
},
109-
icon: path.join(__dirname, 'renderer/assets/images/agent-app-icon.png'),
109+
icon: path.join(import.meta.dirname, 'renderer/assets/images/agent-app-icon.png'),
110110
backgroundColor: await getWindowBackgroundColor(),
111111
show: false
112112
});
@@ -125,7 +125,7 @@ async function createWindow() {
125125
// and load the index.html of the app.
126126

127127
win.loadURL(url.format({
128-
pathname: path.join(__dirname, 'renderer/index.html'),
128+
pathname: path.join(import.meta.dirname, 'renderer/index.html'),
129129
protocol: 'file:',
130130
slashes: true
131131
}));

packages/uhk-agent/webpack.config.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ module.exports = {
1313
path: rootDir + "/dist",
1414
filename: "electron-main.js"
1515
},
16-
target: 'electron-main',
16+
target: 'electron42.4-main',
17+
experiments: {
18+
outputModule: true,
19+
},
20+
externalsType: 'module',
1721
externals: {
18-
"node-hid": "require('node-hid')",
19-
"serialport": "require('serialport')",
22+
"node-hid": "node-hid",
23+
"serialport": "serialport",
2024
},
2125
devtool: 'source-map',
2226
resolve: {
@@ -52,9 +56,4 @@ module.exports = {
5256
webpackHelper.root(__dirname, './src') // location of your src
5357
)
5458
],
55-
node: {
56-
__dirname: false,
57-
__filename: false
58-
}
59-
6059
}

0 commit comments

Comments
 (0)