-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
77 lines (59 loc) · 1.56 KB
/
build.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
const rollup = require( 'rollup' );
const babel = require( 'rollup-plugin-babel' );
const fs = require( 'fs' );
const writeFile = ( fileName, data ) => {
fs.writeFileSync( fileName, data, 'utf8' );
};
const inputFile = 'src/index.js';
const outputFile = 'build/index.js';
const defaultPlugins = [
// nodeResolve(),
// commonjs(),
babel( {
compact: false,
exclude: ['node_modules/**', 'src/shaders/**'],
babelrc: false,
// plugins: [
// 'external-helpers',
// ],
presets: [
['env',
{
modules: false,
targets: {
browsers: [ 'last 2 versions', '> 5%' ],
},
} ],
],
} ),
];
// rollup inputOptions
const inputOptions = () => {
return {
input: inputFile,
plugins: defaultPlugins,
perf: true,
};
};
// rollup outputOptions
const outputOptions = () => {
return {
file: outputFile,
format: 'iife',
name: 'output',
};
};
// stderr to stderr to keep `rollup main.js > bundle.js` from breaking
const stderr = console.error.bind( console );
async function build( inputOpts, outputOpts ) {
// create a bundle
const bundle = await rollup.rollup( inputOpts );
// generate code and a sourcemap
const { code, map } = await bundle.generate( outputOpts );
console.log( 'Writing file: ' + outputOpts.file );
writeFile( outputOpts.file, code );
console.log( 'Generated bundle: ', bundle.getTimings()[ '# GENERATE' ] );
}
const inputOpts = inputOptions( inputFile );
const outputOpts = outputOptions( inputFile );
build( inputOpts, outputOpts );