Skip to content

Commit f206cc6

Browse files
committed
fix(build): VUE_APP env vars not available in build
1 parent 364e77b commit f206cc6

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

__tests__/commands.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ describe('electron:build', () => {
273273

274274
test('Env vars prefixed with VUE_APP_ are available in main process config', async () => {
275275
process.env.VUE_APP_TEST = 'expected'
276-
await runCommand('electron:serve')
276+
await runCommand('electron:build')
277277
const mainConfig = webpack.mock.calls[0][0]
278278
// Env var is set correctly
279279
expect(mainConfig.plugins[1].defaultValues.VUE_APP_TEST).toBe('expected')

index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ function bundleMain ({
501501
.path(api.resolve(outputDir + (isBuild ? '/bundled' : '')))
502502
// Electron will not detect background.js on dev server, only index.js
503503
.filename('[name].js')
504+
const envVars = {}
504505
if (isBuild) {
505506
// Set __static to __dirname (files in public get copied here)
506507
config
@@ -513,20 +514,19 @@ function bundleMain ({
513514
__static: JSON.stringify(api.resolve('./public'))
514515
}
515516
])
516-
const envVars = {
517-
// Dev server url
518-
WEBPACK_DEV_SERVER_URL: server.url,
519-
// Path to node_modules (for externals in development)
520-
NODE_MODULES_PATH: api.resolve('./node_modules')
521-
}
522-
// Add all env vars prefixed with VUE_APP_
523-
Object.keys(process.env).forEach(k => {
524-
if (/^VUE_APP_/.test(k)) {
525-
envVars[k] = process.env[k]
526-
}
527-
})
528-
config.plugin('env').use(webpack.EnvironmentPlugin, [envVars])
517+
// Dev server url
518+
envVars['WEBPACK_DEV_SERVER_URL'] = server.url
519+
// Path to node_modules (for externals in development)
520+
envVars['NODE_MODULES_PATH'] = api.resolve('./node_modules')
529521
}
522+
// Add all env vars prefixed with VUE_APP_
523+
Object.keys(process.env).forEach(k => {
524+
if (/^VUE_APP_/.test(k)) {
525+
envVars[k] = process.env[k]
526+
}
527+
})
528+
config.plugin('env').use(webpack.EnvironmentPlugin, [envVars])
529+
530530
if (args.debug) {
531531
// Enable source maps for debugging
532532
config.devtool('source-map')

0 commit comments

Comments
 (0)