rollup.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import glob from 'glob'
  2. import { babel } from '@rollup/plugin-babel'
  3. import { nodeResolve } 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. nodeResolve(),
  30. commonjs(),
  31. babel({
  32. babelHelpers: 'bundled',
  33. exclude: 'node_modules/**'
  34. }),
  35. copy({
  36. targets: [
  37. { src: 'src/themes/bootstrap-table/fonts/*', dest: 'dist/themes/bootstrap-table/fonts' }
  38. ]
  39. })
  40. ]
  41. if (process.env.NODE_ENV === 'production') {
  42. plugins.push(terser({
  43. output: {
  44. comments () {
  45. return false
  46. }
  47. }
  48. }))
  49. }
  50. for (const file of files) {
  51. let out = `dist/${file.replace('src/', '')}`
  52. if (process.env.NODE_ENV === 'production') {
  53. out = out.replace(/.js$/, '.min.js')
  54. }
  55. config.push({
  56. input: file,
  57. output: {
  58. name: 'BootstrapTable',
  59. file: out,
  60. format: 'umd',
  61. globals
  62. },
  63. external,
  64. plugins
  65. })
  66. }
  67. let out = 'dist/bootstrap-table-locale-all.js'
  68. if (process.env.NODE_ENV === 'production') {
  69. out = out.replace(/.js$/, '.min.js')
  70. }
  71. config.push({
  72. input: 'src/locale/**/*.js',
  73. output: {
  74. name: 'BootstrapTable',
  75. file: out,
  76. format: 'umd',
  77. globals
  78. },
  79. external,
  80. plugins: [
  81. multiEntry(),
  82. ...plugins
  83. ]
  84. })
  85. out = 'dist/bootstrap-table-vue.js'
  86. if (process.env.NODE_ENV === 'production') {
  87. out = out.replace(/.js$/, '.min.js')
  88. }
  89. config.push({
  90. input: 'src/vue/index.js',
  91. output: {
  92. name: 'BootstrapTable',
  93. file: out,
  94. format: 'umd'
  95. },
  96. plugins: [
  97. vue(),
  98. ...plugins
  99. ]
  100. })
  101. out = 'dist/bootstrap-table-vue.esm.js'
  102. if (process.env.NODE_ENV === 'production') {
  103. out = out.replace(/.js$/, '.min.js')
  104. }
  105. config.push({
  106. input: 'src/vue/BootstrapTable.vue',
  107. output: {
  108. name: 'BootstrapTable',
  109. file: out,
  110. format: 'esm'
  111. },
  112. plugins: [
  113. vue(),
  114. ...plugins
  115. ]
  116. })
  117. export default config