rollup.config.js 2.5 KB

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