rollup-examples.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var path = require( 'path' );
  2. var fs = require( 'fs' );
  3. // Creates a rollup config object for the given file to
  4. // be converted to umd
  5. function createOutput( file ) {
  6. var inputPath = path.resolve( file );
  7. var outputPath = inputPath.replace( /[\\\/]examples[\\\/]jsm[\\\/]/, '/examples/js/' );
  8. // Every import is marked as external so the output is 1-to-1. We
  9. // assume that that global object should be the THREE object so we
  10. // replicate the existing behavior.
  11. return {
  12. input: inputPath,
  13. treeshake: false,
  14. external: p => p !== inputPath,
  15. output: {
  16. format: 'umd',
  17. name: 'THREE',
  18. file: outputPath,
  19. globals: () => 'THREE',
  20. paths: p => /three\.module\.js$/.test( p ) ? 'three' : p,
  21. extend: true,
  22. banner:
  23. '/**\n' +
  24. ` * Generated from '${ path.relative( '.', inputPath.replace( /\\/, '/' ) ) }'\n` +
  25. ' */\n'
  26. }
  27. };
  28. }
  29. // Walk the file structure starting at the given directory and fire
  30. // the callback for every file.
  31. function walk( dir, cb ) {
  32. var files = fs.readdirSync( dir );
  33. files.forEach( f => {
  34. var p = path.join( dir, f );
  35. var stats = fs.statSync( p );
  36. if ( stats.isDirectory() ) {
  37. walk( p, cb );
  38. } else {
  39. cb( p );
  40. }
  41. } );
  42. }
  43. // Gather up all the files
  44. var files = [];
  45. walk( 'examples/jsm/', p => files.push( p ) );
  46. // Create a rollup config for each module.js file
  47. export default files.map( p => createOutput( p ) );