import typescript from '@rollup/plugin-typescript'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; const target = process.env.TARGET || 'node'; const config = { input: target === 'browser' ? 'src/browser.ts' : 'src/node.ts', plugins: [ resolve(), commonjs(), typescript({ tsconfig: './tsconfig.json', declaration: false, declarationDir: undefined }) ] }; // Extensions are explicit rather than bare `.js`: the package is not // "type": "module", so Node treats a .js file as CommonJS. An ES-format bundle // named .js therefore fails to import on Node < 22, and only works above that // because Node re-parses it after guessing — at a cost on every import. if (target === 'node') { config.output = [ { file: 'dist/node/index.js', format: 'cjs', exports: 'named' }, { file: 'dist/esm/index.mjs', format: 'es' } ]; config.external = ['crypto', 'https', 'fs', 'path']; } else if (target === 'browser') { config.output = [ { file: 'dist/browser/index.mjs', format: 'es', name: 'Nomyo' }, { file: 'dist/browser/index.cjs', format: 'cjs', exports: 'named', name: 'Nomyo' } ]; } export default config;