rollup.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import glob from 'glob'
  2. import babel from 'rollup-plugin-babel'
  3. import resolve from 'rollup-plugin-node-resolve'
  4. import commonjs from 'rollup-plugin-commonjs'
  5. import { terser } from 'rollup-plugin-terser'
  6. import inject from 'rollup-plugin-inject'
  7. import copy from 'rollup-plugin-copy'
  8. import multiEntry from 'rollup-plugin-multi-entry'
  9. import vue from 'rollup-plugin-vue'
  10. const files = glob.sync('src/**/*.js', {
  11. ignore: [
  12. 'src/constants/**',
  13. 'src/utils/**',
  14. 'src/virtual-scroll/**',
  15. 'src/vue/**'
  16. ]
  17. })
  18. const external = ['jquery']
  19. const globals = {
  20. jquery: 'jQuery'
  21. }
  22. const config = []
  23. const plugins = [
  24. inject({
  25. include: '**/*.js',
  26. exclude: 'node_modules/**',
  27. $: 'jquery'
  28. }),
  29. resolve(),
  30. commonjs(),
  31. babel({
  32. exclude: 'node_modules/**'
  33. }),
  34. copy({
  35. targets: [
  36. { src: 'src/themes/bootstrap-table/fonts/*', dest: 'dist/themes/bootstrap-table/fonts' }
  37. ]
  38. })
  39. ]
  40. if (process.env.NODE_ENV === 'production') {
  41. plugins.push(terser({
  42. output: {
  43. comments () {
  44. return false
  45. }
  46. }
  47. }))
  48. }
  49. for (const file of files) {
  50. let out = `dist/${file.replace('src/', '')}`
  51. if (process.env.NODE_ENV === 'production') {
  52. out = out.replace(/.js$/, '.min.js')
  53. }
  54. config.push({
  55. input: file,
  56. output: {
  57. name: 'BootstrapTable',
  58. file: out,
  59. format: 'umd',
  60. globals
  61. },
  62. external,
  63. plugins
  64. })
  65. }
  66. let out = 'dist/bootstrap-table-locale-all.js'
  67. if (process.env.NODE_ENV === 'production') {
  68. out = out.replace(/.js$/, '.min.js')
  69. }
  70. config.push({
  71. input: 'src/locale/**/*.js',
  72. output: {
  73. name: 'BootstrapTable',
  74. file: out,
  75. format: 'umd',
  76. globals
  77. },
  78. external,
  79. plugins: [
  80. multiEntry(),
  81. ...plugins
  82. ]
  83. })
  84. out = 'dist/bootstrap-table-vue.js'
  85. if (process.env.NODE_ENV === 'production') {
  86. out = out.replace(/.js$/, '.min.js')
  87. }
  88. config.push({
  89. input: 'src/vue/index.js',
  90. output: {
  91. name: 'BootstrapTable',
  92. file: out,
  93. format: 'umd'
  94. },
  95. plugins: [
  96. vue(),
  97. ...plugins
  98. ]
  99. })
  100. out = 'dist/bootstrap-table-vue.esm.js'
  101. if (process.env.NODE_ENV === 'production') {
  102. out = out.replace(/.js$/, '.min.js')
  103. }
  104. config.push({
  105. input: 'src/vue/BootstrapTable.vue',
  106. output: {
  107. name: 'BootstrapTable',
  108. file: out,
  109. format: 'esm'
  110. },
  111. plugins: [
  112. vue(),
  113. ...plugins
  114. ]
  115. })
  116. export default config