|  | 
|  | 1 | +import { readFileSync } from 'node:fs' | 
|  | 2 | +import commonjs from '@rollup/plugin-commonjs' | 
|  | 3 | +import json from '@rollup/plugin-json' | 
|  | 4 | +import resolve from '@rollup/plugin-node-resolve' | 
|  | 5 | +import terser from '@rollup/plugin-terser' | 
|  | 6 | +import esbuild from 'rollup-plugin-esbuild' | 
|  | 7 | + | 
|  | 8 | +const pkg = JSON.parse(readFileSync('./package.json', 'utf-8')) | 
|  | 9 | + | 
|  | 10 | +// External dependencies for main build | 
|  | 11 | +const external = [ | 
|  | 12 | +  ...Object.keys(pkg.dependencies || {}), | 
|  | 13 | +  ...Object.keys(pkg.peerDependencies || {}), | 
|  | 14 | +] | 
|  | 15 | + | 
|  | 16 | +// Base ESBuild config | 
|  | 17 | +const esbuildBase = { | 
|  | 18 | +  include: /\.ts$/, | 
|  | 19 | +  exclude: /node_modules/, | 
|  | 20 | +  sourceMap: false, | 
|  | 21 | +  minify: false, | 
|  | 22 | +  target: 'es2017', | 
|  | 23 | +  tsconfig: './tsconfig.json', | 
|  | 24 | +  loaders: { | 
|  | 25 | +    '.ts': 'ts', | 
|  | 26 | +  }, | 
|  | 27 | +} | 
|  | 28 | + | 
|  | 29 | +// Main library config (external dependencies) | 
|  | 30 | +export const mainConfig = { | 
|  | 31 | +  input: 'src/index.ts', | 
|  | 32 | +  output: [ | 
|  | 33 | +    { | 
|  | 34 | +      file: pkg.main, | 
|  | 35 | +      format: 'cjs', | 
|  | 36 | +    }, | 
|  | 37 | +    { | 
|  | 38 | +      file: pkg.module, | 
|  | 39 | +      format: 'es', | 
|  | 40 | +    }, | 
|  | 41 | +  ], | 
|  | 42 | +  external, | 
|  | 43 | +  plugins: [esbuild(esbuildBase)], | 
|  | 44 | +} | 
|  | 45 | + | 
|  | 46 | +// Serverless bundled config | 
|  | 47 | +const serverlessPlugins = [ | 
|  | 48 | +  resolve({ | 
|  | 49 | +    preferBuiltins: false, | 
|  | 50 | +    browser: true, | 
|  | 51 | +  }), | 
|  | 52 | +  commonjs(), | 
|  | 53 | +  json(), | 
|  | 54 | +  esbuild(esbuildBase), | 
|  | 55 | +] | 
|  | 56 | + | 
|  | 57 | +export const serverlessConfig = [ | 
|  | 58 | +  // ESM build | 
|  | 59 | +  { | 
|  | 60 | +    input: 'src/index.serverless.ts', | 
|  | 61 | +    output: { | 
|  | 62 | +      file: 'lib/serverless.esm.js', | 
|  | 63 | +      format: 'es', | 
|  | 64 | +    }, | 
|  | 65 | +    plugins: serverlessPlugins, | 
|  | 66 | +  }, | 
|  | 67 | +  // ESM minified | 
|  | 68 | +  { | 
|  | 69 | +    input: 'src/index.serverless.ts', | 
|  | 70 | +    output: { | 
|  | 71 | +      file: 'lib/serverless.esm.min.js', | 
|  | 72 | +      format: 'es', | 
|  | 73 | +    }, | 
|  | 74 | +    plugins: [ | 
|  | 75 | +      ...serverlessPlugins, | 
|  | 76 | +      terser({ | 
|  | 77 | +        compress: { | 
|  | 78 | +          drop_console: true, | 
|  | 79 | +          passes: 2, | 
|  | 80 | +        }, | 
|  | 81 | +        mangle: true, | 
|  | 82 | +      }), | 
|  | 83 | +    ], | 
|  | 84 | +  }, | 
|  | 85 | +  // CommonJS build | 
|  | 86 | +  { | 
|  | 87 | +    input: 'src/index.serverless.ts', | 
|  | 88 | +    output: { | 
|  | 89 | +      file: 'lib/serverless.cjs.js', | 
|  | 90 | +      format: 'cjs', | 
|  | 91 | +      exports: 'named', | 
|  | 92 | +    }, | 
|  | 93 | +    plugins: serverlessPlugins, | 
|  | 94 | +  }, | 
|  | 95 | +  // UMD build for browsers | 
|  | 96 | +  { | 
|  | 97 | +    input: 'src/index.serverless.ts', | 
|  | 98 | +    output: { | 
|  | 99 | +      file: 'lib/serverless.umd.js', | 
|  | 100 | +      format: 'umd', | 
|  | 101 | +      name: 'PhoneNumberValidator', | 
|  | 102 | +      exports: 'named', | 
|  | 103 | +    }, | 
|  | 104 | +    plugins: serverlessPlugins, | 
|  | 105 | +  }, | 
|  | 106 | +  // UMD minified | 
|  | 107 | +  { | 
|  | 108 | +    input: 'src/index.serverless.ts', | 
|  | 109 | +    output: { | 
|  | 110 | +      file: 'lib/serverless.umd.min.js', | 
|  | 111 | +      format: 'umd', | 
|  | 112 | +      name: 'PhoneNumberValidator', | 
|  | 113 | +      exports: 'named', | 
|  | 114 | +    }, | 
|  | 115 | +    plugins: [ | 
|  | 116 | +      ...serverlessPlugins, | 
|  | 117 | +      terser({ | 
|  | 118 | +        compress: { | 
|  | 119 | +          drop_console: true, | 
|  | 120 | +          passes: 2, | 
|  | 121 | +        }, | 
|  | 122 | +        mangle: true, | 
|  | 123 | +      }), | 
|  | 124 | +    ], | 
|  | 125 | +  }, | 
|  | 126 | +] | 
|  | 127 | + | 
|  | 128 | +// Export all configs | 
|  | 129 | +export default [mainConfig, ...serverlessConfig] | 
0 commit comments