56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
// Build the single-file CDN bundle: everything a browser needs as one
|
|||
|
|
// minified ES module, for import-map use against any static host that
|
||
|
|
// serves JavaScript with the right MIME type.
|
||
|
|
//
|
||
|
|
// npm run bundle → dist-cdn/buuh.js (+ sourcemap)
|
||
|
|
//
|
||
|
|
// <script type="importmap">
|
||
|
|
// { "imports": { "buuh": "https://cdn.uhhm.no/buuh@8.0.0.js" } }
|
||
|
|
// </script>
|
||
|
|
// <script type="module">
|
||
|
|
// import { choo, html } from 'buuh'
|
||
|
|
// </script>
|
||
|
|
|
||
|
|
import { build } from 'vite'
|
||
|
|
import { readFile } from 'node:fs/promises'
|
||
|
|
import { join, dirname, resolve } from 'node:path'
|
||
|
|
import { fileURLToPath } from 'node:url'
|
||
|
|
|
||
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||
|
|
const { version } = JSON.parse(await readFile(join(root, 'packages/core/package.json'), 'utf8'))
|
||
|
|
|
||
|
|
const VIRTUAL = '\0bundle:entry'
|
||
|
|
|
||
|
|
await build({
|
||
|
|
appType: 'custom',
|
||
|
|
logLevel: 'warn',
|
||
|
|
plugins: [{
|
||
|
|
name: 'bundle-entry',
|
||
|
|
resolveId: (id) => id === 'bundle:entry' ? VIRTUAL : undefined,
|
||
|
|
load: (id) => id === VIRTUAL
|
||
|
|
? [
|
||
|
|
"export { default as choo, Choo, lazy } from '@uhhm/buuh'",
|
||
|
|
"export { default as html } from '@uhhm/buuh-html'",
|
||
|
|
"export { default as raw } from '@uhhm/buuh-html/raw'",
|
||
|
|
"export { default as morph } from '@uhhm/buuh-html/morph'",
|
||
|
|
"export { default as hydrate } from '@uhhm/buuh-html/hydrate'",
|
||
|
|
"export { default as Component } from '@uhhm/buuh-component'",
|
||
|
|
"export { default as devtools } from '@uhhm/buuh-devtools'"
|
||
|
|
].join('\n')
|
||
|
|
: undefined
|
||
|
|
}],
|
||
|
|
build: {
|
||
|
|
outDir: join(root, 'dist-cdn'),
|
||
|
|
emptyOutDir: true,
|
||
|
|
sourcemap: true,
|
||
|
|
lib: false,
|
||
|
|
rollupOptions: {
|
||
|
|
input: { buuh: 'bundle:entry' },
|
||
|
|
output: { entryFileNames: 'buuh.js' },
|
||
|
|
preserveEntrySignatures: 'strict'
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
console.log(`bundled buuh ${version} → dist-cdn/buuh.js`)
|