Skip to content

Commit

Permalink
fix: svite config
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Mar 11, 2021
1 parent 8a38b93 commit 458ef8c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions configs/svite-routify.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@ module.exports = {
supersedes: ['routify2', 'routify'],
condition: ({ pkgjson }) => pkgjson.dependencies['@svitejs/vite-plugin-svelte'],
config: () => {
const { readFileSync } = require('fs')
const html = readFileSync('./dist/index.html', 'utf8')
const script = html.match(/<script .+?src="([^"]+)"/)[1]
return {
const config = {
sitemap: '.routify/urlIndex.json',
script: `dist${script}`,
entrypoint: 'dist/index.html',
inlineDynamicImports: true,
outputDir: 'dist',
eventName: 'app-loaded',
}

const script = getScript(config.entrypoint)
if (script)
config.script = `dist${script}`

return config
}
}

function getScript(entrypoint) {
const { readFileSync, existsSync } = require('fs')
if (existsSync(entrypoint))
return readFileSync(entrypoint, 'utf8')
.match(/<script .+?src="([^"]+)"/)[1]
}

0 comments on commit 458ef8c

Please sign in to comment.