rollup.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import buble from 'rollup-plugin-buble';
  2. function glconstants() {
  3. var constants = {
  4. POINTS: 0, ZERO: 0,
  5. LINES: 1, ONE: 1,
  6. LINE_LOOP: 2,
  7. LINE_STRIP: 3,
  8. TRIANGLES: 4,
  9. TRIANGLE_STRIP: 5,
  10. TRIANGLE_FAN: 6,
  11. DEPTH_BUFFER_BIT: 256,
  12. LESS: 513,
  13. NEVER: 512,
  14. EQUAL: 514,
  15. LEQUAL: 515,
  16. GREATER: 516,
  17. NOTEQUAL: 517,
  18. GEQUAL: 518,
  19. ALWAYS: 519,
  20. SRC_COLOR: 768,
  21. ONE_MINUS_SRC_COLOR: 769,
  22. SRC_ALPHA: 770,
  23. ONE_MINUS_SRC_ALPHA: 771,
  24. DST_ALPHA: 772,
  25. ONE_MINUS_DST_ALPHA: 773,
  26. DST_COLOR: 774,
  27. ONE_MINUS_DST_COLOR: 775,
  28. SRC_ALPHA_SATURATE: 776,
  29. STENCIL_BUFFER_BIT: 1024,
  30. FRONT: 1028,
  31. BACK: 1029,
  32. FRONT_AND_BACK: 1032,
  33. CW: 2304,
  34. CCW: 2305,
  35. CULL_FACE: 2884,
  36. DEPTH_TEST: 2929,
  37. STENCIL_TEST: 2960,
  38. BLEND: 3042,
  39. SCISSOR_TEST: 3089,
  40. UNPACK_ALIGNMENT: 3317,
  41. MAX_TEXTURE_SIZE: 3379,
  42. DEPTH24_STENCIL8: 35056,
  43. TEXTURE_2D: 3553,
  44. BYTE: 5120,
  45. UNSIGNED_BYTE: 5121,
  46. SHORT: 5122,
  47. UNSIGNED_INT: 5125,
  48. UNSIGNED_SHORT: 5123,
  49. INT: 5124,
  50. FLOAT: 5126,
  51. HALF_FLOAT: 5131,
  52. DEPTH_COMPONENT: 6402,
  53. RED: 6403,
  54. ALPHA: 6406,
  55. RGB: 6407,
  56. RGBA: 6408,
  57. LUMINANCE: 6409,
  58. LUMINANCE_ALPHA: 6410,
  59. RED_INTEGER: 36244,
  60. RG: 33319,
  61. RG_INTEGER: 33320,
  62. RGB_INTEGER: 36248,
  63. RGBA_INTEGER: 36249,
  64. VERSION: 7938,
  65. NEAREST: 9728,
  66. LINEAR: 9729,
  67. NEAREST_MIPMAP_NEAREST: 9984,
  68. LINEAR_MIPMAP_NEAREST: 9985,
  69. NEAREST_MIPMAP_LINEAR: 9986,
  70. LINEAR_MIPMAP_LINEAR: 9987,
  71. TEXTURE_MAG_FILTER: 10240,
  72. TEXTURE_MIN_FILTER: 10241,
  73. TEXTURE_WRAP_S: 10242,
  74. TEXTURE_WRAP_T: 10243,
  75. TEXTURE_WRAP_R: 32882,
  76. REPEAT: 10497,
  77. COLOR_BUFFER_BIT: 16384,
  78. FUNC_ADD: 32774,
  79. MIN: 32775,
  80. MAX: 32776,
  81. FUNC_SUBTRACT: 32778,
  82. FUNC_REVERSE_SUBTRACT: 32779,
  83. UNSIGNED_SHORT_4_4_4_4: 32819,
  84. UNSIGNED_SHORT_5_5_5_1: 32820,
  85. POLYGON_OFFSET_FILL: 32823,
  86. RGB8: 32849,
  87. RGBA4: 32854,
  88. RGBA8: 32856,
  89. TEXTURE_3D: 32879,
  90. CLAMP_TO_EDGE: 33071,
  91. DEPTH_COMPONENT16: 33189,
  92. DEPTH_STENCIL_ATTACHMENT: 33306,
  93. R8: 33321,
  94. R16F: 33325,
  95. R32F: 33326,
  96. UNSIGNED_SHORT_5_6_5: 33635,
  97. MIRRORED_REPEAT: 33648,
  98. TEXTURE0: 33984,
  99. DEPTH_STENCIL: 34041,
  100. UNSIGNED_INT_24_8: 34042,
  101. TEXTURE_CUBE_MAP: 34067,
  102. TEXTURE_CUBE_MAP_POSITIVE_X: 34069,
  103. MAX_CUBE_MAP_TEXTURE_SIZE: 34076,
  104. COMPRESSED_TEXTURE_FORMATS: 34467,
  105. RGBA32F: 34836,
  106. RGB32F: 34837,
  107. RGBA16F: 34842,
  108. RGB16F: 34843,
  109. MAX_VERTEX_ATTRIBS: 34921,
  110. MAX_TEXTURE_IMAGE_UNITS: 34930,
  111. ARRAY_BUFFER: 34962,
  112. ELEMENT_ARRAY_BUFFER: 34963,
  113. STATIC_DRAW: 35044,
  114. DYNAMIC_DRAW: 35048,
  115. VERTEX_SHADER: 35633,
  116. FRAGMENT_SHADER: 35632,
  117. MAX_VERTEX_TEXTURE_IMAGE_UNITS: 35660,
  118. MAX_COMBINED_TEXTURE_IMAGE_UNITS: 35661,
  119. COMPILE_STATUS: 35713,
  120. LINK_STATUS: 35714,
  121. VALIDATE_STATUS: 35715,
  122. ACTIVE_UNIFORMS: 35718,
  123. ACTIVE_ATTRIBUTES: 35721,
  124. IMPLEMENTATION_COLOR_READ_TYPE: 35738,
  125. IMPLEMENTATION_COLOR_READ_FORMAT: 35739,
  126. TEXTURE_2D_ARRAY: 35866,
  127. DEPTH_COMPONENT32F: 36012,
  128. COLOR_ATTACHMENT0: 36064,
  129. FRAMEBUFFER_COMPLETE: 36053,
  130. DEPTH_ATTACHMENT: 36096,
  131. FRAMEBUFFER: 36160,
  132. RENDERBUFFER: 36161,
  133. LOW_FLOAT: 36336,
  134. MEDIUM_FLOAT: 36337,
  135. HIGH_FLOAT: 36338,
  136. MAX_VERTEX_UNIFORM_VECTORS: 36347,
  137. MAX_VARYING_VECTORS: 36348,
  138. MAX_FRAGMENT_UNIFORM_VECTORS: 36349,
  139. UNPACK_FLIP_Y_WEBGL: 37440,
  140. UNPACK_PREMULTIPLY_ALPHA_WEBGL: 37441,
  141. MAX_SAMPLES: 36183,
  142. READ_FRAMEBUFFER: 36008,
  143. DRAW_FRAMEBUFFER: 36009
  144. };
  145. return {
  146. transform( code ) {
  147. code = code.replace( /_?gl\.([A-Z0-9_]+)/g, function ( match, p1 ) {
  148. if ( p1 in constants ) return constants[ p1 ];
  149. console.log( '* Unhandled GL Constant:', p1 );
  150. return match;
  151. } );
  152. return {
  153. code: code,
  154. map: { mappings: '' }
  155. };
  156. }
  157. };
  158. }
  159. function glsl() {
  160. return {
  161. transform( code, id ) {
  162. if ( /\.glsl.js$/.test( id ) === false ) return;
  163. code = code.replace( /\/\* glsl \*\/\`((.*|\n|\r\n)*)\`/, function ( match, p1 ) {
  164. return JSON.stringify(
  165. p1
  166. .trim()
  167. .replace( /\r/g, '' )
  168. .replace( /[ \t]*\/\/.*\n/g, '' ) // remove //
  169. .replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' ) // remove /* */
  170. .replace( /\n{2,}/g, '\n' ) // # \n+ to \n
  171. );
  172. } );
  173. return {
  174. code: code,
  175. map: { mappings: '' }
  176. };
  177. }
  178. };
  179. }
  180. export default [
  181. {
  182. input: 'src/Three.js',
  183. plugins: [
  184. glconstants(),
  185. glsl(),
  186. buble( {
  187. transforms: {
  188. arrow: false,
  189. classes: true
  190. }
  191. } )
  192. ],
  193. output: [
  194. {
  195. format: 'umd',
  196. name: 'THREE',
  197. file: 'build/three.js',
  198. indent: '\t'
  199. }
  200. ]
  201. },
  202. {
  203. input: 'src/Three.js',
  204. plugins: [
  205. glconstants(),
  206. glsl()
  207. ],
  208. output: [
  209. {
  210. format: 'esm',
  211. file: 'build/three.module.js',
  212. indent: '\t'
  213. }
  214. ]
  215. }
  216. ];