rollup.config.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { globSync } 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. const files = globSync('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. nodeResolve(),
  29. commonjs(),
  30. babel({
  31. babelHelpers: 'bundled',
  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. export default config