UNPKG

uni-analytics-sdk

Version:

A universal SDK for analytics and logging.

89 lines (80 loc) 2.56 kB
/** * @fileoverview This is the configuration file for Rollup, which is used to * bundle the Universal SDK into various formats for distribution (CommonJS, ESM, UMD). */ import typescript from '@rollup/plugin-typescript'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import terser from '@rollup/plugin-terser'; import { dts } from 'rollup-plugin-dts'; import polyfillNode from 'rollup-plugin-polyfill-node'; // FIX: Import the newly installed alias plugin. import alias from '@rollup/plugin-alias'; import fs from 'fs'; // FIX: Import path and url to correctly resolve file paths in an ES Module context. import path from 'path'; import { fileURLToPath } from 'url'; const packageJson = JSON.parse(fs.readFileSync(path.resolve('./package.json'), 'utf-8')); const umdGlobalName = 'UniversalSDK'; // Helper to resolve the project root directory. const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); export default [ // --- Main Bundles (CommonJS and ES Module) --- { input: 'src/index.ts', output: [ { file: packageJson.main, // dist/index.cjs.js format: 'cjs', sourcemap: true, }, { file: packageJson.module, // dist/index.esm.js format: 'esm', sourcemap: true, }, ], plugins: [ nodeResolve(), commonjs(), typescript({ tsconfig: './tsconfig.json' }), ], external: ['tslib'], }, // --- Browser UMD Bundle (for CDN and direct script tags) --- { input: 'src/index.ts', output: { file: packageJson.browser, // dist/sdk.min.js format: 'umd', name: umdGlobalName, sourcemap: true, }, plugins: [ nodeResolve({ browser: true }), commonjs(), polyfillNode(), typescript({ tsconfig: './tsconfig.json' }), terser(), ] }, // --- TypeScript Declaration File Bundle --- { input: 'dist/types/index.d.ts', output: [{ file: 'dist/index.d.ts', format: 'esm' }], plugins: [ dts(), // FIX: Add the alias plugin to resolve the '@/' path alias inside the .d.ts files. alias({ entries: [ { find: '@', // This tells Rollup that '@/' should point to the root of our generated types directory. replacement: path.resolve(__dirname, 'dist/types') } ] }) ], }, ];