rollup.config.js 2.4 KB

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