Skip to content

Commit 4cee541

Browse files
committed
add typescript support in main process
1 parent f7d9fc3 commit 4cee541

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ module.exports = (api, options) => {
66
options.pluginOptions && options.pluginOptions.electronBuilder
77
? options.pluginOptions.electronBuilder
88
: {}
9+
const usesTypescript = pluginOptions.disableBackgroundTypescript
10+
? false
11+
: api.hasPlugin('typescript')
12+
const backgroundTypeChecking = pluginOptions.backgroundTypeChecking || false
913
const outputDir = pluginOptions.outputDir || 'dist_electron'
10-
const backgroundFile = pluginOptions.backgroundFile || 'src/background.js'
14+
const backgroundFile =
15+
pluginOptions.backgroundFile ||
16+
(usesTypescript ? 'src/background.ts' : 'src/background.js')
1117
api.registerCommand(
1218
'build:electron',
1319
{
@@ -54,6 +60,15 @@ module.exports = (api, options) => {
5460
.plugin('env')
5561
.use(webpack.EnvironmentPlugin, [{ NODE_ENV: 'production' }])
5662
mainConfig.entry('background').add(api.resolve(backgroundFile))
63+
if (usesTypescript) {
64+
mainConfig.resolve.extensions.merge(['.ts'])
65+
mainConfig.module
66+
.rule('ts')
67+
.test(/\.ts$/)
68+
.use('ts-loader')
69+
.loader('ts-loader')
70+
.options({ transpileOnly: !backgroundTypeChecking })
71+
}
5772

5873
console.log('Bundling render process:')
5974
rendererConfig.target('electron-renderer').output.publicPath('./')
@@ -144,6 +159,16 @@ module.exports = (api, options) => {
144159
.plugin('env')
145160
.use(webpack.EnvironmentPlugin, [{ NODE_ENV: 'development' }])
146161
mainConfig.entry('background').add(api.resolve(backgroundFile))
162+
if (usesTypescript) {
163+
mainConfig.resolve.extensions.merge(['.ts'])
164+
mainConfig.module
165+
.rule('ts')
166+
.test(/\.ts$/)
167+
.use('ts-loader')
168+
.loader('ts-loader')
169+
.options({ transpileOnly: !backgroundTypeChecking })
170+
}
171+
147172
const bundle = webpack(mainConfig.toConfig())
148173

149174
console.log('Bundling main process:\n')

0 commit comments

Comments
 (0)