rollup-examples.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. extend: true,
  21. banner:
  22. '/**\n' +
  23. ` * Generated from '${ path.relative( '.', inputPath.replace( /\\/, '/' ) ) }'\n` +
  24. ' **/\n'
  25. }
  26. };
  27. }
  28. // Walk the file structure starting at the given directory and fire
  29. // the callback for every file.
  30. function walk( dir, cb ) {
  31. var files = fs.readdirSync( dir );
  32. files.forEach( f => {
  33. var p = path.join( dir, f );
  34. var stats = fs.statSync( p );
  35. if ( stats.isDirectory() ) {
  36. walk( p, cb );
  37. } else {
  38. cb( p );
  39. }
  40. } );
  41. }
  42. // Gather up all the files
  43. var files = [];
  44. walk( 'examples/jsm/', p => files.push( p ) );
  45. // Create a rollup config for each module.js file
  46. export default files.map( p => createOutput( p ) );