rollup.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import terser from '@rollup/plugin-terser';
  2. import MagicString from 'magic-string';
  3. function glsl() {
  4. return {
  5. transform( code, id ) {
  6. if ( /\.glsl.js$/.test( id ) === false ) return;
  7. code = new MagicString( code );
  8. code.replace( /\/\* glsl \*\/\`(.*?)\`/sg, function ( match, p1 ) {
  9. return JSON.stringify(
  10. p1
  11. .trim()
  12. .replace( /\r/g, '' )
  13. .replace( /[ \t]*\/\/.*\n/g, '' ) // remove //
  14. .replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' ) // remove /* */
  15. .replace( /\n{2,}/g, '\n' ) // # \n+ to \n
  16. );
  17. } );
  18. return {
  19. code: code.toString(),
  20. map: code.generateMap()
  21. };
  22. }
  23. };
  24. }
  25. function header() {
  26. return {
  27. renderChunk( code ) {
  28. code = new MagicString( code );
  29. code.prepend( `/**
  30. * @license
  31. * Copyright 2010-2025 Three.js Authors
  32. * SPDX-License-Identifier: MIT
  33. */\n` );
  34. return {
  35. code: code.toString(),
  36. map: code.generateMap()
  37. };
  38. }
  39. };
  40. }
  41. /**
  42. * @type {Array<import('rollup').RollupOptions>}
  43. */
  44. const builds = [
  45. {
  46. input: {
  47. 'three.core.js': 'src/Three.Core.js',
  48. 'three.webgpu.nodes.js': 'src/Three.WebGPU.Nodes.js',
  49. },
  50. plugins: [
  51. glsl(),
  52. header()
  53. ],
  54. preserveEntrySignatures: 'allow-extension',
  55. output: [
  56. {
  57. format: 'esm',
  58. dir: 'build',
  59. minifyInternalExports: false,
  60. entryFileNames: '[name]',
  61. }
  62. ]
  63. },
  64. {
  65. input: {
  66. 'three.core.js': 'src/Three.Core.js',
  67. 'three.module.js': 'src/Three.js',
  68. 'three.webgpu.js': 'src/Three.WebGPU.js',
  69. },
  70. plugins: [
  71. glsl(),
  72. header()
  73. ],
  74. preserveEntrySignatures: 'allow-extension',
  75. output: [
  76. {
  77. format: 'esm',
  78. dir: 'build',
  79. minifyInternalExports: false,
  80. entryFileNames: '[name]',
  81. }
  82. ]
  83. },
  84. {
  85. input: {
  86. 'three.tsl.js': 'src/Three.TSL.js',
  87. },
  88. plugins: [
  89. header()
  90. ],
  91. preserveEntrySignatures: 'allow-extension',
  92. output: [
  93. {
  94. format: 'esm',
  95. dir: 'build',
  96. minifyInternalExports: false,
  97. entryFileNames: '[name]',
  98. }
  99. ],
  100. external: [ 'three/webgpu' ]
  101. },
  102. {
  103. input: {
  104. 'three.core.min.js': 'src/Three.Core.js',
  105. 'three.webgpu.nodes.min.js': 'src/Three.WebGPU.Nodes.js',
  106. },
  107. plugins: [
  108. glsl(),
  109. header(),
  110. terser()
  111. ],
  112. preserveEntrySignatures: 'allow-extension',
  113. output: [
  114. {
  115. format: 'esm',
  116. dir: 'build',
  117. minifyInternalExports: false,
  118. entryFileNames: '[name]',
  119. }
  120. ]
  121. },
  122. {
  123. input: {
  124. 'three.core.min.js': 'src/Three.Core.js',
  125. 'three.module.min.js': 'src/Three.js',
  126. 'three.webgpu.min.js': 'src/Three.WebGPU.js',
  127. },
  128. plugins: [
  129. glsl(),
  130. header(),
  131. terser()
  132. ],
  133. preserveEntrySignatures: 'allow-extension',
  134. output: [
  135. {
  136. format: 'esm',
  137. dir: 'build',
  138. minifyInternalExports: false,
  139. entryFileNames: '[name]',
  140. }
  141. ]
  142. },
  143. {
  144. input: {
  145. 'three.tsl.min.js': 'src/Three.TSL.js'
  146. },
  147. plugins: [
  148. header(),
  149. terser()
  150. ],
  151. preserveEntrySignatures: 'allow-extension',
  152. output: [
  153. {
  154. format: 'esm',
  155. dir: 'build',
  156. minifyInternalExports: false,
  157. entryFileNames: '[name]',
  158. }
  159. ],
  160. external: [ 'three/webgpu' ]
  161. },
  162. {
  163. input: 'src/Three.js',
  164. plugins: [
  165. glsl(),
  166. header()
  167. ],
  168. output: [
  169. {
  170. format: 'cjs',
  171. name: 'THREE',
  172. file: 'build/three.cjs',
  173. indent: '\t'
  174. }
  175. ]
  176. }
  177. ];
  178. export default ( args ) => args.configOnlyModule ? builds.slice( 0, 3 ) : builds;
粤ICP备19079148号