Skip to content

Commit bafd557

Browse files
committed
fix(build): fails with multiple pages, closes 182
1 parent 387734f commit bafd557

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

__tests__/commands.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,35 @@ describe('electron:build', () => {
317317
expect(options.baseUrl).toBe('expected')
318318
expect(options.publicPath).toBe('expected')
319319
})
320+
321+
test('Adds mock legacy assets file for index', async () => {
322+
await runCommand('electron:build')
323+
expect(fs.writeFileSync).toBeCalledWith(
324+
'dist_electron/bundled/legacy-assets-index.html.json',
325+
'[]'
326+
)
327+
})
328+
329+
test.each(['string config', 'object config'])(
330+
'Adds mock legacy assets file for each page (%s)',
331+
async configType => {
332+
const stringConfig = configType === 'string config'
333+
await runCommand('electron:build', {
334+
pages: {
335+
index: stringConfig ? '' : { fileName: 'index.html' },
336+
subpage: stringConfig ? '' : { fileName: 'subpage.html' }
337+
}
338+
})
339+
expect(fs.writeFileSync).toBeCalledWith(
340+
'dist_electron/bundled/legacy-assets-index.html.json',
341+
'[]'
342+
)
343+
expect(fs.writeFileSync).toBeCalledWith(
344+
'dist_electron/bundled/legacy-assets-subpage.html.json',
345+
'[]'
346+
)
347+
}
348+
)
320349
})
321350

322351
describe('electron:serve', () => {

index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,17 @@ module.exports = (api, options) => {
111111
fs.removeSync(bundleOutputDir)
112112
fs.ensureDirSync(bundleOutputDir)
113113
// Mock data from legacy build
114-
fs.writeFileSync(
115-
path.join(bundleOutputDir, 'legacy-assets-index.html.json'),
116-
'[]'
117-
)
114+
const pages = options.pages || { index: '' }
115+
Object.keys(pages).forEach(page => {
116+
if (pages[page].fileName) {
117+
// If page is configured as an object, use the filename (without .html)
118+
page = pages[page].fileName.replace(/\.html$/, '')
119+
}
120+
fs.writeFileSync(
121+
path.join(bundleOutputDir, `legacy-assets-${page}.html.json`),
122+
'[]'
123+
)
124+
})
118125
// Set the base url so that the app protocol is used
119126
options.baseUrl = pluginOptions.customFileProtocol || 'app://./'
120127
// Set publicPath as well (replaced baseUrl since @vue/cli 3.3.0)

0 commit comments

Comments
 (0)