rollup.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. // rollup.config.js
  5. import { readdirSync } from 'fs'
  6. import { terser } from 'rollup-plugin-terser'
  7. import resolve from '@rollup/plugin-node-resolve'
  8. import commonjs from '@rollup/plugin-commonjs'
  9. import sucrase from '@rollup/plugin-sucrase'
  10. import babel, { getBabelOutputPlugin } from '@rollup/plugin-babel'
  11. import typescript from '@rollup/plugin-typescript'
  12. import pkg from './package.json'
  13. export default [
  14. {
  15. input: (() => {
  16. let input = {}
  17. readdirSync('src')
  18. .filter((e) => e.endsWith('.ts') && e !== 'bundle.ts')
  19. .forEach((mod) => (input[`${mod.replace('.ts', '')}`] = `./src/${mod}`))
  20. return input
  21. })(),
  22. treeshake: true,
  23. perf: true,
  24. output: [
  25. {
  26. dir: 'dist/',
  27. entryFileNames: '[name].cjs',
  28. format: 'cjs',
  29. chunkFileNames: '[name]-[hash].cjs',
  30. exports: 'named',
  31. globals: {}
  32. },
  33. {
  34. dir: 'dist/',
  35. entryFileNames: '[name].js',
  36. format: 'esm',
  37. exports: 'named',
  38. globals: {}
  39. }
  40. ],
  41. plugins: [
  42. commonjs({}),
  43. resolve({
  44. // pass custom options to the resolve plugin
  45. customResolveOptions: {
  46. moduleDirectories: ['node_modules']
  47. }
  48. }),
  49. typescript({
  50. tsconfig: './tsconfig.json'
  51. }),
  52. babel({
  53. configFile: false,
  54. presets: [['@babel/preset-env'], ['@babel/preset-typescript']]
  55. }),
  56. terser()
  57. ],
  58. external: [
  59. ...Object.keys(pkg.dependencies || {}),
  60. ...Object.keys(pkg.peerDependencies || {})
  61. ]
  62. },
  63. {
  64. input: {
  65. bundle: './src/bundle.ts'
  66. },
  67. output: [
  68. {
  69. name: '__TAURI__',
  70. dir: '../../core/tauri/scripts',
  71. entryFileNames: 'bundle.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. moduleDirectories: ['node_modules']
  92. }
  93. })
  94. ],
  95. external: [
  96. ...Object.keys(pkg.dependencies || {}),
  97. ...Object.keys(pkg.peerDependencies || {})
  98. ]
  99. }
  100. ]