rollup.treeshake.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { gzipSync } from 'zlib';
  2. import resolve from '@rollup/plugin-node-resolve';
  3. import terser from '@rollup/plugin-terser';
  4. function filesize() {
  5. const green = '\x1b[1m\x1b[32m';
  6. const yellow = '\x1b[33m';
  7. const reset = '\x1b[0m';
  8. return {
  9. name: 'filesize',
  10. writeBundle( options, bundle ) {
  11. for ( const [ , chunk ] of Object.entries( bundle ) ) {
  12. if ( chunk.code ) {
  13. const size = ( chunk.code.length / 1024 ).toFixed( 2 ) + ' KB';
  14. const gzipped = ( gzipSync( chunk.code ).length / 1024 ).toFixed( 2 ) + ' KB';
  15. const destination = options.file;
  16. const lines = [
  17. { label: 'Destination: ', value: destination },
  18. { label: 'Bundle Size: ', value: size },
  19. { label: 'Gzipped Size: ', value: gzipped }
  20. ];
  21. const maxLength = Math.max( ...lines.map( l => l.label.length + l.value.length ) );
  22. const width = maxLength + 6;
  23. console.log( `\n┌${'─'.repeat( width )}┐` );
  24. console.log( `│${' '.repeat( width )}│` );
  25. lines.forEach( ( { label, value } ) => {
  26. const padding = ' '.repeat( width - label.length - value.length - 3 );
  27. console.log( `│ ${green}${label}${yellow}${value}${reset}${padding}│` );
  28. } );
  29. console.log( `│${' '.repeat( width )}│` );
  30. console.log( `└${'─'.repeat( width )}┘` );
  31. }
  32. }
  33. }
  34. };
  35. }
  36. export default [
  37. {
  38. input: 'test/treeshake/index.js',
  39. plugins: [
  40. resolve()
  41. ],
  42. output: [
  43. {
  44. format: 'esm',
  45. file: 'test/treeshake/index.bundle.js'
  46. }
  47. ]
  48. },
  49. {
  50. input: 'test/treeshake/index.js',
  51. plugins: [
  52. resolve(),
  53. terser(),
  54. filesize()
  55. ],
  56. output: [
  57. {
  58. format: 'esm',
  59. file: 'test/treeshake/index.bundle.min.js'
  60. }
  61. ]
  62. },
  63. {
  64. input: 'test/treeshake/index.webgpu.js',
  65. plugins: [
  66. resolve()
  67. ],
  68. output: [
  69. {
  70. format: 'esm',
  71. file: 'test/treeshake/index.webgpu.bundle.js'
  72. }
  73. ]
  74. },
  75. {
  76. input: 'test/treeshake/index.webgpu.js',
  77. plugins: [
  78. resolve(),
  79. terser(),
  80. filesize()
  81. ],
  82. output: [
  83. {
  84. format: 'esm',
  85. file: 'test/treeshake/index.webgpu.bundle.min.js'
  86. }
  87. ]
  88. },
  89. {
  90. input: 'test/treeshake/index.webgpu.nodes.js',
  91. plugins: [
  92. resolve()
  93. ],
  94. output: [
  95. {
  96. format: 'esm',
  97. file: 'test/treeshake/index.webgpu.nodes.bundle.js'
  98. }
  99. ]
  100. },
  101. {
  102. input: 'test/treeshake/index.webgpu.nodes.js',
  103. plugins: [
  104. resolve(),
  105. terser(),
  106. filesize()
  107. ],
  108. output: [
  109. {
  110. format: 'esm',
  111. file: 'test/treeshake/index.webgpu.nodes.bundle.min.js'
  112. }
  113. ]
  114. }
  115. ];
粤ICP备19079148号