-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15526 from gkjohnson/rollup-jsm-examples
Add Rollup Config to module examples to UMD
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
var path = require( 'path' ); | ||
var fs = require( 'fs' ); | ||
|
||
// Creates a rollup config object for the given file to | ||
// be converted to umd | ||
function createOutput( file ) { | ||
|
||
var inputPath = path.resolve( file ); | ||
var outputPath = inputPath.replace( /[\\\/]examples[\\\/]jsm[\\\/]/, '/examples/js/' ); | ||
|
||
// Every import is marked as external so the output is 1-to-1. We | ||
// assume that that global object should be the THREE object so we | ||
// replicate the existing behavior. | ||
return { | ||
|
||
input: inputPath, | ||
treeshake: false, | ||
external: p => p !== inputPath, | ||
|
||
output: { | ||
|
||
format: 'umd', | ||
name: 'THREE', | ||
file: outputPath, | ||
|
||
globals: () => 'THREE', | ||
paths: p => /three\.module\.js$/.test( p ) ? 'three' : p, | ||
extend: true, | ||
|
||
banner: | ||
'/**\n' + | ||
` * Generated from '${ path.relative( '.', inputPath.replace( /\\/, '/' ) ) }'\n` + | ||
' */\n' | ||
|
||
} | ||
|
||
}; | ||
|
||
} | ||
|
||
// Walk the file structure starting at the given directory and fire | ||
// the callback for every file. | ||
function walk( dir, cb ) { | ||
|
||
var files = fs.readdirSync( dir ); | ||
files.forEach( f => { | ||
|
||
var p = path.join( dir, f ); | ||
var stats = fs.statSync( p ); | ||
if ( stats.isDirectory() ) { | ||
|
||
walk( p, cb ); | ||
|
||
} else { | ||
|
||
cb( p ); | ||
|
||
} | ||
|
||
} ); | ||
|
||
} | ||
|
||
// Gather up all the files | ||
var files = []; | ||
walk( 'examples/jsm/', p => files.push( p ) ); | ||
|
||
// Create a rollup config for each module.js file | ||
export default files.map( p => createOutput( p ) ); |