import resolve from '@rollup/plugin-node-resolve';import babel from '@rollup/plugin-babel';import { terser } from 'rollup-plugin-terser';import pkg from './package.json';import typescript from 'rollup-plugin-typescript2';import { wasm } from '@rollup/plugin-wasm';import url from '@rollup/plugin-url';
const LIBRARY_NAME = 'Library'; const EXTERNAL = []; const GLOBALS = {};
const banner = `/*! * ${pkg.name} * ${pkg.description} * * @version v${pkg.version} * @author ${pkg.author} * @homepage ${pkg.homepage} * @repository ${pkg.repository.url} * @license ${pkg.license} */`;
const makeConfig = (env = 'development') => { let bundleSuffix = '';
if (env === 'production') { bundleSuffix = 'min.'; }
const config = { input: 'lib.ts', external: EXTERNAL, output: [ { banner, name: LIBRARY_NAME, file: `dist/${LIBRARY_NAME}.umd.${bundleSuffix}js`, format: 'umd', exports: 'auto', globals: GLOBALS }, { banner, file: `dist/${LIBRARY_NAME}.cjs.${bundleSuffix}js`, format: 'cjs', exports: 'auto', globals: GLOBALS }, { banner, file: `dist/${LIBRARY_NAME}.esm.${bundleSuffix}js`, format: 'es', exports: 'named', globals: GLOBALS } ], plugins: [ url({ include: ['**/*.wasm'], limit: 14336000, }), resolve(), typescript({ rollupCommonJSResolveHack: false, clean: true, }) ] };
if (env === 'production') { config.plugins.push(terser({ output: { comments: /^!/ } })); }
return config;};
export default commandLineArgs => { const configs = [ makeConfig() ];
if (commandLineArgs.environment === 'BUILD:production') { configs.push(makeConfig('production')); }
return configs;};