rollup.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. process: './src/process.ts',
  19. tauri: './src/tauri.ts',
  20. window: './src/window.ts',
  21. cli: './src/cli.ts',
  22. notification: './src/notification.ts'
  23. },
  24. treeshake: true,
  25. perf: true,
  26. output: [
  27. {
  28. dir: 'dist/',
  29. entryFileNames: '[name].js',
  30. format: 'cjs',
  31. exports: 'named',
  32. globals: {}
  33. },
  34. {
  35. dir: 'dist/',
  36. entryFileNames: '[name].mjs',
  37. format: 'esm',
  38. exports: 'named',
  39. globals: {}
  40. }
  41. ],
  42. plugins: [
  43. commonjs({}),
  44. resolve({
  45. // pass custom options to the resolve plugin
  46. customResolveOptions: {
  47. moduleDirectory: 'node_modules'
  48. }
  49. }),
  50. typescript({
  51. tsconfig: './tsconfig.json'
  52. }),
  53. babel({
  54. configFile: false,
  55. presets: [['@babel/preset-env'], ['@babel/preset-typescript']]
  56. }),
  57. terser()
  58. ],
  59. external: [
  60. ...Object.keys(pkg.dependencies || {}),
  61. ...Object.keys(pkg.peerDependencies || {})
  62. ],
  63. watch: {
  64. chokidar: true,
  65. include: 'src/**',
  66. exclude: 'node_modules/**'
  67. }
  68. },
  69. {
  70. input: {
  71. bundle: './src/bundle.ts'
  72. },
  73. output: [
  74. {
  75. name: '__TAURI__',
  76. dir: 'dist/', // 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. }
  106. ]