forked from nglviewer/ngl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
80 lines (76 loc) · 1.92 KB
/
rollup.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
import buble from 'rollup-plugin-buble';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
var path = require('path');
var pkg = require('./package.json');
var external = Object.keys(pkg.dependencies);
function glsl () {
return {
name: "glsl",
transform: function( code, id ) {
if ( !/\.(glsl|frag|vert)$/.test( id ) ) return;
var src, key;
if( path.basename( path.dirname( id ) ) === 'shader' ){
src = "../globals.js";
key = "shader/" + path.basename( id );
}else{
src = "../../globals.js";
key = "shader/chunk/" + path.basename( id );
}
var registryImport = 'import { ShaderRegistry } from "' + src + '";';
var shader = JSON.stringify(
code
.replace( /[ \t]*\/\/.*\n/g, '' )
.replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' )
.replace( /\n{2,}/g, '\n' )
.replace( /\t/g, ' ' )
.replace( / {2,}/g, ' ' )
.replace( / *\n */g, '\n' )
);
var register = "ShaderRegistry.add('" + key + "', " + shader + ");";
code = registryImport + register;
return { code: code, map: { mappings: "" } };
}
};
}
function text () {
return {
name: "text",
transform: function( code, id ) {
if ( !/\.(txt)$/.test( id ) ) return;
code = 'export default ' + JSON.stringify( code ) + ';';
return { code: code, map: { mappings: "" } };
}
};
}
export default {
input: 'src/ngl.js',
plugins: [
resolve({
jsnext: true,
main: true
}),
commonjs(),
glsl(),
text(),
json(),
buble()
],
output: [
{
file: "build/js/ngl.dev.js",
format: 'umd',
name: 'NGL',
sourcemap: true
},
{
file: "build/js/ngl.esm.js",
format: 'es',
name: 'NGL',
sourcemap: true
}
],
external: external,
sourcemap: true
};