Carlos Santos f3405abadb Copies bundle to CE and Pro backend
Copies the generated bundle to both the CE and Pro backend directories during the build process.

This ensures that the webcomponent is readily available for both versions, streamlining the deployment process.
It also introduces improved logging and error handling to provide better visibility into the copying process.
2025-10-16 18:21:15 +02:00

115 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// rollup.config.js
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
import terser from '@rollup/plugin-terser'
import postcss from 'rollup-plugin-postcss'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const production = !process.env.ROLLUP_WATCH
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
export default {
input: 'src/index.ts',
output: {
file: './dist/openvidu-meet.bundle.min.js',
format: 'iife',
name: 'OpenViduMeet',
sourcemap: !production
},
plugins: [
resolve({
// Prioritize modern ES modules
mainFields: ['module', 'browser', 'main']
}),
commonjs({
// Optimize CommonJS conversion
transformMixedEsModules: true
}),
postcss({
inject: true, // This injects the CSS into the JS bundle
minimize: true,
// Don't extract CSS to a separate file
extract: false
}),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
sourceMap: !production
}),
terser({
ecma: 2020, // Use modern features when possible
compress: {
drop_console: {
log: production, // Remove console.logs in production
warn: true,
error: true
},
drop_debugger: production,
pure_getters: true,
unsafe: true,
passes: 3, // Multiple passes for better minification
toplevel: true // Enable top-level variable renaming
},
// mangle: {
// properties: {
// regex: /^_|^iframe|^error|^load|^allowed|^command|^events/, // Mangle most internal properties
// reserved: [
// 'connectedCallback',
// 'disconnectedCallback', // Web Component lifecycle methods
// 'shadowRoot',
// 'attachShadow', // Shadow DOM APIs
// 'attributes',
// 'setAttribute' // Standard element properties
// ]
// },
// toplevel: true // Enable top-level variable renaming
// },
format: {
comments: !production
}
}),
{
name: 'copy-bundle',
writeBundle () {
const bundleName = 'openvidu-meet.bundle.min.js'
const sourcePath = path.resolve(__dirname, './dist', bundleName)
if (!fs.existsSync(sourcePath)) {
console.warn(`⚠️ Bundle not found at ${sourcePath}, skipping copy.`)
return
}
// 1. Copy to CE backend
const ceDir = path.resolve(__dirname, '../../backend/public/webcomponent')
try {
if (!fs.existsSync(ceDir)) fs.mkdirSync(ceDir, { recursive: true })
fs.copyFileSync(sourcePath, path.join(ceDir, bundleName))
console.log(`✅ Bundle copied to CE: ${ceDir}/${bundleName}`)
} catch (err) {
console.error(`❌ Failed to copy bundle to CE: ${err}`)
}
// 2. Copy to Pro backend if it exists
const proDir = path.resolve(__dirname, '../../../meet-pro')
const webcomponentProDir = path.join(proDir, 'backend/public/webcomponent')
try {
if (fs.existsSync(proDir) && fs.lstatSync(proDir).isDirectory()) {
if (!fs.existsSync(webcomponentProDir)) fs.mkdirSync(webcomponentProDir, { recursive: true })
fs.copyFileSync(sourcePath, path.join(webcomponentProDir, bundleName))
console.log(`✅ Bundle copied to PRO: ${webcomponentProDir}/${bundleName}`)
} else {
console.log(` PRO directory does not exist, skipping copy: ${proDir}`)
}
} catch (err) {
console.error(`❌ Failed to copy bundle to PRO: ${err}`)
}
}
}
]
}