Skip to content

Commit

Permalink
fix(player): cdn breaking due to mangle cache being created late
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Dec 11, 2023
1 parent ff7b9f3 commit 6cd1dee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
26 changes: 7 additions & 19 deletions packages/react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';

import { nodeResolve } from '@rollup/plugin-node-resolve';
import chokidar from 'chokidar';
import { build, transformSync } from 'esbuild';
import { build } from 'esbuild';
import fs from 'fs-extra';
import { globbySync } from 'globby';
import { defineConfig } from 'rollup';
Expand All @@ -13,6 +13,9 @@ import esbuildPlugin from 'rollup-plugin-esbuild';
const MODE_WATCH = process.argv.includes('-w'),
MODE_TYPES = process.argv.includes('--config-types');

/** @type {Record<string, string | false>} */
const MANGLE_CACHE = !MODE_TYPES ? await buildMangleCache() : {};

const DIRNAME = path.dirname(fileURLToPath(import.meta.url)),
ROOT_DIR = path.resolve(DIRNAME, '.'),
STYLES_DIR = path.resolve(ROOT_DIR, 'player/styles'),
Expand All @@ -31,9 +34,6 @@ const EXTERNAL_PACKAGES = [
NPM_BUNDLES = [define({ dev: true }), define({ dev: false })],
TYPES_BUNDLES = [defineTypes()];

/** @type {Record<string, string | false>} */
const MANGLE_CACHE = !MODE_TYPES ? await buildMangleCache() : {};

// Styles
if (!MODE_TYPES) {
copyStyles();
Expand Down Expand Up @@ -157,25 +157,13 @@ function define({ dev }) {
tsconfig: 'tsconfig.build.json',
target: 'es2021',
platform: 'browser',
mangleProps: !dev ? /^_/ : undefined,
mangleCache: !dev ? MANGLE_CACHE : undefined,
reserveProps: !dev ? /^__/ : undefined,
define: {
__DEV__: dev ? 'true' : 'false',
},
}),
!dev && {
name: 'mangle',
transform(code) {
const result = transformSync(code, {
target: 'esnext',
minify: false,
mangleProps: /^_/,
reserveProps: /^__/,
mangleCache: MANGLE_CACHE,
loader: 'tsx',
});

return result.code;
},
},
{
name: 'rsc-directives',
resolveId(id) {
Expand Down
26 changes: 7 additions & 19 deletions packages/vidstack/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'node:fs/promises';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import chokidar from 'chokidar';
import * as eslexer from 'es-module-lexer';
import { build, transformSync } from 'esbuild';
import { build } from 'esbuild';
import { globbySync } from 'globby';
import { defineConfig } from 'rollup';
import dts from 'rollup-plugin-dts';
Expand All @@ -13,15 +13,15 @@ const MODE_WATCH = process.argv.includes('-w'),
MODE_TYPES = process.argv.includes('--config-types'),
MODE_CDN = process.argv.includes('--config-cdn');

/** @type {Record<string, string | false>} */
const MANGLE_CACHE = !MODE_TYPES ? await buildMangleCache() : {};

const NPM_EXTERNAL_PACKAGES = ['hls.js', 'media-captions', 'media-icons'],
CDN_EXTERNAL_PACKAGES = ['media-captions', 'media-icons'],
NPM_BUNDLES = [define({ type: 'server' }), define({ type: 'dev' }), define({ type: 'prod' })],
CDN_BUNDLES = [defineCDN({ dev: true }), defineCDN(), defineCDN({ layouts: true })],
TYPES_BUNDLES = [defineTypes()];

/** @type {Record<string, string | false>} */
const MANGLE_CACHE = !MODE_TYPES ? await buildMangleCache() : {};

// Styles
if (!MODE_TYPES) {
if (MODE_WATCH) {
Expand Down Expand Up @@ -121,7 +121,6 @@ function define({ target, type, minify }) {

return {
input,
maxParallelFileOps: shouldMangle ? 1 : 20,
treeshake: true,
preserveEntrySignatures: 'strict',
external: NPM_EXTERNAL_PACKAGES,
Expand Down Expand Up @@ -158,26 +157,15 @@ function define({ target, type, minify }) {
}
},
},
shouldMangle && {
name: 'mangle',
transform(code) {
const result = transformSync(code, {
target: 'esnext',
minify: false,
mangleProps: /^_/,
mangleCache: MANGLE_CACHE,
loader: 'tsx',
});

return result.code;
},
},
esbuildPlugin({
tsconfig: 'tsconfig.build.json',
target: target ?? (isServer ? 'node18' : 'esnext'),
platform: isServer ? 'node' : 'browser',
minify: minify,
legalComments: 'none',
mangleProps: shouldMangle ? /^_/ : undefined,
mangleCache: shouldMangle ? MANGLE_CACHE : undefined,
reserveProps: shouldMangle ? /^__/ : undefined,
define: {
__DEV__: !isProd && !isServer ? 'true' : 'false',
__SERVER__: isServer ? 'true' : 'false',
Expand Down

0 comments on commit 6cd1dee

Please sign in to comment.