forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup-examples.config.js
85 lines (55 loc) · 1.63 KB
/
rollup-examples.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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,
plugins: [ {
generateBundle: function ( options, bundle ) {
for ( var key in bundle ) {
bundle[ key ].code = bundle[ key ].code.replace( /three_module_js/g, 'THREE' );
}
}
} ],
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( /\\/g, '/' ) }'\n` +
' */\n',
esModule: false
}
};
}
// Walk the file structure starting at the given directory and fire
// the callback for every js 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 if ( f.endsWith( '.js' ) ) {
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 ) );