Skip to content

Commit

Permalink
Merge pull request #5340 from video-dev/task/rollup-esm-and-worker-tj
Browse files Browse the repository at this point in the history
More rollup PR tweaks
  • Loading branch information
tjenkinson committed Mar 26, 2023
2 parents 39682b6 + e5dccfa commit 185b254
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ coverage/
/cloudflare-pages
/api-docs
/api-docs-markdown
/karma-temp

# eslint
.eslintcache
Expand Down
22 changes: 15 additions & 7 deletions build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const addContentSteeringSupport =
const addVariableSubstitutionSupport =
!!env.VARIABLE_SUBSTITUTION || !!env.USE_VARIABLE_SUBSTITUTION;

const buildConstants = (type, format) => ({
const shouldBundleWorker = (format) => format !== FORMAT.esm;

const buildConstants = (type, additional = {}) => ({
preventAssignment: true,
values: {
__VERSION__: JSON.stringify(pkgJson.version),
Expand All @@ -60,6 +62,7 @@ const buildConstants = (type, format) => ({
__USE_VARIABLE_SUBSTITUTION__: JSON.stringify(
type === BUILD_TYPE.full || addVariableSubstitutionSupport
),
...additional,
},
});

Expand Down Expand Up @@ -240,16 +243,19 @@ const buildRollupConfig = ({
? `./dist/${outputName}.min.${extension}`
: `./dist/${outputName}.${extension}`,
format,
banner: format === FORMAT.esm ? null : workerFnBanner,
footer: format === FORMAT.esm ? null : workerFnFooter,
banner: shouldBundleWorker(format) ? workerFnBanner : null,
footer: shouldBundleWorker(format) ? workerFnFooter : null,
sourcemap,
sourcemapFile: minified
? `${outputName}.${extension}.min.map`
: `${outputName}.${extension}.map`,
},
plugins: [
...basePlugins,
replace(buildConstants(type, format)),
replace(buildConstants(type)),
...(!shouldBundleWorker(format)
? [alias({ entries: { './transmuxer-worker': '../empty.js' } })]
: []),
...(type === BUILD_TYPE.light
? [alias({ entries: getAliasesForLightDist() })]
: []),
Expand Down Expand Up @@ -300,14 +306,16 @@ const configs = Object.entries({
name: 'HlsWorker',
file: './dist/hls.worker.js',
format: FORMAT.iife,
banner: workerFnBanner,
footer: workerFnFooter.replace('false', 'true'),
sourcemap: true,
sourcemapFile: 'hls.worker.js.map',
},
plugins: [
...basePlugins,
replace(buildConstants(BUILD_TYPE.full, FORMAT.iife)),
replace(
buildConstants(BUILD_TYPE.full, {
__IN_WORKER__: JSON.stringify(true),
})
),
buildBabelLegacyBrowsers({ stripConsole: true }),
terser(),
],
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const rollupPreprocessor = buildRollupConfig({
allowCircularDeps: true,
includeCoverage,
sourcemap: false,
outputFile: 'temp/tests.js',
outputFile: 'karma-temp/tests.js',
});

// preprocess matching files before serving them to the browser
Expand Down
4 changes: 4 additions & 0 deletions src/demux/inject-worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// ensure the worker ends up in the bundle
// If the worker should not be included this gets aliased to empty.js
import './transmuxer-worker';

export function hasUMDWorker(): boolean {
return typeof __HLS_WORKER_BUNDLE__ === 'function';
}
Expand Down

0 comments on commit 185b254

Please sign in to comment.