rollup.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import babel from '@rollup/plugin-babel';
  2. import commonjs from '@rollup/plugin-commonjs';
  3. import copy from 'rollup-plugin-copy';
  4. function generateConfig(configType) {
  5. const config = {
  6. input: 'client/token.js',
  7. plugins: [
  8. babel({
  9. configFile: './babel.rollup.config.json',
  10. exclude: 'node_modules/**',
  11. babelHelpers: 'runtime',
  12. }),
  13. commonjs(),
  14. copy({
  15. targets: [{src: 'module.d.ts', dest: 'lib', rename: 'index.d.ts'}],
  16. }),
  17. ],
  18. };
  19. switch (configType) {
  20. case 'browser':
  21. // TODO: Add support
  22. break;
  23. case 'node':
  24. config.output = [
  25. {
  26. file: 'lib/index.cjs.js',
  27. format: 'cjs',
  28. sourcemap: true,
  29. },
  30. {
  31. file: 'lib/index.esm.js',
  32. format: 'es',
  33. sourcemap: true,
  34. },
  35. ];
  36. // Quash 'Unresolved dependencies' complaints for modules listed in the
  37. // package.json "dependencies" section. Unfortunately this list is manually
  38. // maintained.
  39. config.external = [
  40. 'assert',
  41. '@babel/runtime/core-js/get-iterator',
  42. '@babel/runtime/core-js/json/stringify',
  43. '@babel/runtime/core-js/object/assign',
  44. '@babel/runtime/core-js/object/get-prototype-of',
  45. '@babel/runtime/core-js/object/keys',
  46. '@babel/runtime/core-js/promise',
  47. '@babel/runtime/helpers/asyncToGenerator',
  48. '@babel/runtime/helpers/classCallCheck',
  49. '@babel/runtime/helpers/createClass',
  50. '@babel/runtime/helpers/defineProperty',
  51. '@babel/runtime/helpers/get',
  52. '@babel/runtime/helpers/getPrototypeOf',
  53. '@babel/runtime/helpers/inherits',
  54. '@babel/runtime/helpers/possibleConstructorReturn',
  55. '@babel/runtime/helpers/slicedToArray',
  56. '@babel/runtime/helpers/toConsumableArray',
  57. '@babel/runtime/helpers/typeof',
  58. '@babel/runtime/regenerator',
  59. 'bn.js',
  60. 'buffer-layout',
  61. '@solana/web3.js',
  62. ];
  63. break;
  64. default:
  65. throw new Error(`Unknown configType: ${configType}`);
  66. }
  67. return config;
  68. }
  69. export default [generateConfig('node')];