rollup.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // rollup.config.js
  2. import { terser } from 'rollup-plugin-terser'
  3. import resolve from '@rollup/plugin-node-resolve'
  4. import commonjs from '@rollup/plugin-commonjs'
  5. import sucrase from '@rollup/plugin-sucrase'
  6. import babel, { getBabelOutputPlugin } from '@rollup/plugin-babel'
  7. import typescript from '@rollup/plugin-typescript'
  8. import pkg from './package.json'
  9. export default [{
  10. input: {
  11. 'fs': './api-src/fs.ts',
  12. 'dialog': './api-src/dialog.ts',
  13. 'event': './api-src/event.ts',
  14. 'http': './api-src/http.ts',
  15. 'index': './api-src/index.ts',
  16. 'process': './api-src/process.ts',
  17. 'tauri': './api-src/tauri.ts',
  18. 'window': './api-src/window.ts',
  19. 'cli': './api-src/cli.ts',
  20. 'notification': './api-src/notification.ts',
  21. },
  22. treeshake: true,
  23. perf: true,
  24. output: [
  25. {
  26. dir: 'api/',
  27. entryFileNames: '[name].js',
  28. format: 'cjs',
  29. exports: 'named',
  30. globals: {}
  31. },
  32. {
  33. dir: 'api/',
  34. entryFileNames: '[name].mjs',
  35. format: 'esm',
  36. exports: 'named',
  37. globals: {}
  38. }
  39. ],
  40. plugins: [
  41. commonjs({}),
  42. resolve({
  43. // pass custom options to the resolve plugin
  44. customResolveOptions: {
  45. moduleDirectory: 'node_modules'
  46. }
  47. }),
  48. typescript({
  49. tsconfig: './api-src/tsconfig.json'
  50. }),
  51. babel({
  52. configFile: false,
  53. presets: [
  54. ['@babel/preset-env'],
  55. ['@babel/preset-typescript']
  56. ]
  57. }),
  58. terser()
  59. ],
  60. external: [
  61. ...Object.keys(pkg.dependencies || {}),
  62. ...Object.keys(pkg.peerDependencies || {})
  63. ],
  64. watch: {
  65. chokidar: true,
  66. include: 'api-src/**',
  67. exclude: 'node_modules/**'
  68. }
  69. },
  70. {
  71. input: {
  72. 'bundle': './api-src/bundle.ts'
  73. },
  74. output: [{
  75. name: '__TAURI__',
  76. dir: 'api/', // if it needs to run in the browser
  77. entryFileNames: 'tauri.bundle.umd.js',
  78. format: 'umd',
  79. plugins: [
  80. getBabelOutputPlugin({
  81. presets: [['@babel/preset-env', { modules: 'umd' }]],
  82. allowAllFormats: true
  83. }),
  84. terser()
  85. ],
  86. globals: {
  87. }
  88. }],
  89. plugins: [
  90. sucrase({
  91. exclude: ['node_modules'],
  92. transforms: ['typescript']
  93. }),
  94. resolve({
  95. // pass custom options to the resolve plugin
  96. customResolveOptions: {
  97. moduleDirectory: 'node_modules'
  98. }
  99. })
  100. ],
  101. external: [
  102. ...Object.keys(pkg.dependencies || {}),
  103. ...Object.keys(pkg.peerDependencies || {})
  104. ]
  105. }]