rollup.config.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. function glsl() {
  2. return {
  3. transform( code, id ) {
  4. if ( /\.glsl$/.test( id ) === false ) return;
  5. var transformedCode = 'export default ' + JSON.stringify(
  6. code
  7. .replace( /[ \t]*\/\/.*\n/g, '' )
  8. .replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' )
  9. .replace( /\n{2,}/g, '\n' )
  10. ) + ';';
  11. return {
  12. code: transformedCode,
  13. map: { mappings: '' }
  14. };
  15. }
  16. };
  17. }
  18. export default {
  19. entry: (function () {
  20. var env = process.env.BUILD;
  21. if( env === 'production' ) {
  22. return 'src/Three.js';
  23. } else if( env === 'test' ){
  24. return 'test/Three.Unit.js';
  25. } else {
  26. console.error("Invalid BUILD environment variable: " + env);
  27. return null;
  28. }
  29. })(),
  30. indent: '\t',
  31. plugins: [
  32. glsl()
  33. ],
  34. // sourceMap: true,
  35. targets: (function () {
  36. var env = process.env.BUILD;
  37. if( env === 'production' ) {
  38. return [
  39. {
  40. format: 'umd',
  41. moduleName: 'THREE',
  42. dest: 'build/three.js'
  43. },
  44. {
  45. format: 'es',
  46. dest: 'build/three.module.js'
  47. }
  48. ];
  49. } else if( env === 'test' ){
  50. return [
  51. {
  52. format: 'umd',
  53. moduleName: 'THREE',
  54. dest: 'test/unit/three.unit.js'
  55. }
  56. ];
  57. } else {
  58. console.error("Invalid BUILD environment variable: " + env);
  59. return null;
  60. }
  61. })()
  62. };