File: rollup-examples.config.js

package info (click to toggle)
three.js 111%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 15,212 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (85 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download
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
module.exports = files.map( p => createOutput( p ) );