Skip to content

Commit

Permalink
fix: svite
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Mar 11, 2021
1 parent 6852115 commit 144c88a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions configs/svite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ module.exports = {
condition: ({ pkgjson }) => pkgjson.dependencies['@svitejs/vite-plugin-svelte'],
supersedes: ['default'],
config: () => {
const { readFileSync } = require('fs')
const html = readFileSync('./dist/index.html', 'utf8')
const script = 'dist' + html.match(/<script .+?src="([^"]+)"/)[1]

return {
const config = {
assetsDir: 'dist',
entrypoint: 'dist/index.html',
ssrOptions: { inlineDynamicImports: true },
script
ssrOptions: { inlineDynamicImports: true }
}

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 144c88a

Please sign in to comment.