Skip to content

Commit c2bafe7

Browse files
committed
fix(player): cdn entries need absolute url import specifiers
1 parent b37814c commit c2bafe7

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

packages/vidstack/rollup.config.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import fs from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
24

35
import { nodeResolve } from '@rollup/plugin-node-resolve';
46
import chokidar from 'chokidar';
@@ -289,12 +291,14 @@ function getCDNBundles() {
289291
* @returns {import('rollup').RollupOptions}
290292
*/
291293
function defineCDNBundle({ dev = false, input, dir, file, legacy = false }) {
294+
const npm = defineNPMBundle({
295+
type: dev ? 'dev' : 'prod',
296+
minify: !dev,
297+
target: 'es2020',
298+
});
299+
292300
return {
293-
...defineNPMBundle({
294-
type: dev ? 'dev' : 'prod',
295-
minify: !dev,
296-
target: 'es2020',
297-
}),
301+
...npm,
298302
input: dev ? input : { [file]: input, ...getProviderInputs() },
299303
preserveEntrySignatures: dev ? 'allow-extension' : 'strict',
300304
output: {
@@ -324,6 +328,28 @@ function defineCDNBundle({ dev = false, input, dir, file, legacy = false }) {
324328
},
325329
},
326330
external: CDN_EXTERNAL_PACKAGES,
331+
plugins: [
332+
.../** @type {*} */ (npm.plugins),
333+
{
334+
// This plugin rewrites chunk paths so our URL rewrites to jsDelivr work.
335+
name: 'cdn-chunks',
336+
async generateBundle(_, bundle) {
337+
const __dirname = path.dirname(fileURLToPath(import.meta.url)),
338+
version = JSON.parse(
339+
await fs.readFile(path.join(__dirname, 'package.json'), 'utf-8'),
340+
).version;
341+
342+
for (const chunk of Object.values(bundle)) {
343+
if (chunk.type === 'chunk' && chunk.isEntry && chunk.name === file) {
344+
chunk.code = chunk.code.replace(
345+
/\"\.\/(chunks|providers)\/(.*?)\"/g,
346+
`"https://cdn.jsdelivr.net/npm/@vidstack/cdn@${version}/$1/$2"`,
347+
);
348+
}
349+
}
350+
},
351+
},
352+
],
327353
};
328354
}
329355

0 commit comments

Comments
 (0)