rollup.config.js 2.1 KB

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