rollup.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import MagicString from 'magic-string';
  2. function glsl() {
  3. return {
  4. transform( code, id ) {
  5. if ( /\.glsl.js$/.test( id ) === false ) return;
  6. code = new MagicString( code );
  7. code.replace( /\/\* glsl \*\/\`(.*?)\`/sg, function ( match, p1 ) {
  8. return JSON.stringify(
  9. p1
  10. .trim()
  11. .replace( /\r/g, '' )
  12. .replace( /[ \t]*\/\/.*\n/g, '' ) // remove //
  13. .replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' ) // remove /* */
  14. .replace( /\n{2,}/g, '\n' ) // # \n+ to \n
  15. );
  16. } );
  17. return {
  18. code: code.toString(),
  19. map: code.generateMap()
  20. };
  21. }
  22. };
  23. }
  24. function header() {
  25. return {
  26. renderChunk( code ) {
  27. code = new MagicString( code );
  28. code.prepend( `/**
  29. * @license
  30. * Copyright 2010-2026 Three.js Authors
  31. * SPDX-License-Identifier: MIT
  32. */\n` );
  33. return {
  34. code: code.toString(),
  35. map: code.generateMap()
  36. };
  37. }
  38. };
  39. }
  40. /**
  41. * @type {Array<import('rollup').RollupOptions>}
  42. */
  43. const builds = [
  44. {
  45. input: {
  46. 'three.core.js': 'src/Three.Core.js',
  47. 'three.webgpu.nodes.js': 'src/Three.WebGPU.Nodes.js',
  48. },
  49. plugins: [
  50. glsl(),
  51. header()
  52. ],
  53. preserveEntrySignatures: 'allow-extension',
  54. output: [
  55. {
  56. format: 'esm',
  57. dir: 'build',
  58. minifyInternalExports: false,
  59. entryFileNames: '[name]',
  60. }
  61. ]
  62. },
  63. {
  64. input: {
  65. 'three.core.js': 'src/Three.Core.js',
  66. 'three.module.js': 'src/Three.js',
  67. 'three.webgpu.js': 'src/Three.WebGPU.js',
  68. },
  69. plugins: [
  70. glsl(),
  71. header()
  72. ],
  73. preserveEntrySignatures: 'allow-extension',
  74. output: [
  75. {
  76. format: 'esm',
  77. dir: 'build',
  78. minifyInternalExports: false,
  79. entryFileNames: '[name]',
  80. }
  81. ]
  82. },
  83. {
  84. input: {
  85. 'three.tsl.js': 'src/Three.TSL.js',
  86. },
  87. plugins: [
  88. header()
  89. ],
  90. preserveEntrySignatures: 'allow-extension',
  91. output: [
  92. {
  93. format: 'esm',
  94. dir: 'build',
  95. minifyInternalExports: false,
  96. entryFileNames: '[name]',
  97. }
  98. ],
  99. external: [ 'three/webgpu' ]
  100. }
  101. ];
  102. export default builds;
粤ICP备19079148号