Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bddjr committed Nov 27, 2024
1 parent e0568fd commit 87e9103
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function generateBundle(bundle: OutputBundle, htmlMinifierOptions: htmlMin
console.log(pc.cyan('\n\nvite-plugin-singlefile-compression ') + pc.green('building...'))

const globalDel = new Set<string>()
const globalDoNotDel = new Set<string>()

for (const htmlFileName of Object.keys(bundle)) {
// key format:
Expand Down Expand Up @@ -155,6 +156,10 @@ async function generateBundle(bundle: OutputBundle, htmlMinifierOptions: htmlMin
oldSize += js.code.length
// fix new URL
newJSCode.push(`import.meta.url=location.origin+location.pathname.replace(/[^/]*$/,"${name}")`)
for (const i in assets) {
if (js.code.includes(i))
globalDoNotDel.add(i)
}
// add script
newJSCode.push(js.code.replace(/;?\n?$/, ''))
// gzip
Expand Down Expand Up @@ -184,7 +189,8 @@ async function generateBundle(bundle: OutputBundle, htmlMinifierOptions: htmlMin

// delete inlined assets
for (const name of globalDel) {
delete bundle[name]
if (!globalDoNotDel.has(name))
delete bundle[name]
}
console.log(pc.green('Finish.\n'))
}
2 changes: 2 additions & 0 deletions test/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /

0 comments on commit 87e9103

Please sign in to comment.