@@ -6,8 +6,14 @@ module.exports = (api, options) => {
6
6
options . pluginOptions && options . pluginOptions . electronBuilder
7
7
? options . pluginOptions . electronBuilder
8
8
: { }
9
+ const usesTypescript = pluginOptions . disableBackgroundTypescript
10
+ ? false
11
+ : api . hasPlugin ( 'typescript' )
12
+ const backgroundTypeChecking = pluginOptions . backgroundTypeChecking || false
9
13
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' )
11
17
api . registerCommand (
12
18
'build:electron' ,
13
19
{
@@ -54,6 +60,15 @@ module.exports = (api, options) => {
54
60
. plugin ( 'env' )
55
61
. use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'production' } ] )
56
62
mainConfig . entry ( 'background' ) . add ( api . resolve ( backgroundFile ) )
63
+ if ( usesTypescript ) {
64
+ mainConfig . resolve . extensions . merge ( [ '.ts' ] )
65
+ mainConfig . module
66
+ . rule ( 'ts' )
67
+ . test ( / \. t s $ / )
68
+ . use ( 'ts-loader' )
69
+ . loader ( 'ts-loader' )
70
+ . options ( { transpileOnly : ! backgroundTypeChecking } )
71
+ }
57
72
58
73
console . log ( 'Bundling render process:' )
59
74
rendererConfig . target ( 'electron-renderer' ) . output . publicPath ( './' )
@@ -144,6 +159,16 @@ module.exports = (api, options) => {
144
159
. plugin ( 'env' )
145
160
. use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'development' } ] )
146
161
mainConfig . entry ( 'background' ) . add ( api . resolve ( backgroundFile ) )
162
+ if ( usesTypescript ) {
163
+ mainConfig . resolve . extensions . merge ( [ '.ts' ] )
164
+ mainConfig . module
165
+ . rule ( 'ts' )
166
+ . test ( / \. t s $ / )
167
+ . use ( 'ts-loader' )
168
+ . loader ( 'ts-loader' )
169
+ . options ( { transpileOnly : ! backgroundTypeChecking } )
170
+ }
171
+
147
172
const bundle = webpack ( mainConfig . toConfig ( ) )
148
173
149
174
console . log ( 'Bundling main process:\n' )
0 commit comments