use virtual entrypoints for wrapper bundles
This commit is contained in:
@@ -91,21 +91,35 @@ globalThis.__readability = { Readability, isProbablyReaderable }
|
|||||||
|
|
||||||
async function buildBundle(config: BundleConfig): Promise<void> {
|
async function buildBundle(config: BundleConfig): Promise<void> {
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
let entryPath: string
|
const entrypoint =
|
||||||
let cleanupEntry = false
|
config.type === 'source' ? path.join(srcDir, config.entry) : `virtual:${config.name}`
|
||||||
|
const plugins =
|
||||||
if (config.type === 'source') {
|
config.type === 'source'
|
||||||
entryPath = path.join(srcDir, config.entry)
|
? []
|
||||||
} else {
|
: [
|
||||||
// Create temporary entry file for wrapper bundles
|
{
|
||||||
const entrySuffix = `${process.pid}-${Date.now()}`
|
name: `virtual-${config.name}`,
|
||||||
entryPath = path.join(distDir, `_${config.name}-entry-${entrySuffix}.js`)
|
setup(build) {
|
||||||
fs.writeFileSync(entryPath, config.code)
|
const filter = new RegExp(`^virtual:${config.name}$`)
|
||||||
cleanupEntry = true
|
build.onResolve({ filter }, (args) => {
|
||||||
}
|
return {
|
||||||
|
path: args.path,
|
||||||
|
namespace: 'virtual',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
build.onLoad({ filter, namespace: 'virtual' }, () => {
|
||||||
|
return {
|
||||||
|
contents: config.code,
|
||||||
|
loader: 'js',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
const result = await Bun.build({
|
const result = await Bun.build({
|
||||||
entrypoints: [entryPath],
|
entrypoints: [entrypoint],
|
||||||
|
plugins,
|
||||||
target: 'browser',
|
target: 'browser',
|
||||||
format: 'iife',
|
format: 'iife',
|
||||||
define: {
|
define: {
|
||||||
@@ -113,11 +127,6 @@ async function buildBundle(config: BundleConfig): Promise<void> {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Cleanup temporary entry file
|
|
||||||
if (cleanupEntry && fs.existsSync(entryPath)) {
|
|
||||||
fs.unlinkSync(entryPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
console.error(`Bundle errors for ${config.name}:`, result.logs)
|
console.error(`Bundle errors for ${config.name}:`, result.logs)
|
||||||
throw new Error(`Failed to bundle ${config.name}`)
|
throw new Error(`Failed to bundle ${config.name}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user