This is similar to #43. Vite can be used to bundle the plugin code, and even though it uses Rollup for the production build, it still builds faster than our custom Rollup config. And it can be configured to use Rolldown, which can be even faster.
Here's an example Vite config that seems to work:
import { dirname, resolve, isAbsolute } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import globals from '@jbrowse/core/ReExports/list'
function createGlobalMap(jbrowseGlobals: string[], dotSyntax = false) {
const globalMap: Record<string, string> = {}
for (const global of jbrowseGlobals) {
globalMap[global] = dotSyntax
? `JBrowseExports.${global}`
: `JBrowseExports["${global}"]`
}
return globalMap
}
const __dirname = dirname(fileURLToPath(import.meta.url))
function external(id: string) {
if (id.startsWith('regenerator-runtime')) {
return false
}
return !id.startsWith('.') && !isAbsolute(id)
}
export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'JBrowsePluginTemplate',
fileName: 'jbrowse-plugin-template',
},
rollupOptions: {
external: (id: string) => {
const isExternal = external(id)
if (isExternal && !globals.includes(id)) {
return false
}
return isExternal
},
output: {
globals: createGlobalMap(globals, true),
exports: 'named',
},
},
},
})
This is similar to #43. Vite can be used to bundle the plugin code, and even though it uses Rollup for the production build, it still builds faster than our custom Rollup config. And it can be configured to use Rolldown, which can be even faster.
Here's an example Vite config that seems to work: