-
Notifications
You must be signed in to change notification settings - Fork 170
/
rollup.config.js
110 lines (102 loc) · 2.55 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
var path = require('path')
var pkg = require('./package.json')
// When building UMD or ES6 module, mark dependencies as external
export const moduleExternals = Object.keys(pkg.dependencies)
export const moduleGlobals = {three: 'three'}
export const umdGlobals = {
'chroma-js': 'chroma',
'signals': 'signalsWrapper',
'sprintf-js': 'sprintfJs',
three: 'three'
}
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 const plugins = [
typescript({sourceMap: true, inlineSources: true}),
resolve({
jsnext: true,
main: true,
}),
commonjs(),
glsl(),
text(),
json(),
]
const moduleConfig = {
input: 'src/ngl.ts',
plugins,
output: [
{
file: 'build/js/ngl.umd.js',
format: 'umd',
name: 'NGL',
sourcemap: true,
globals: umdGlobals
},
{
file: 'build/js/ngl.esm.js',
format: 'es',
name: 'NGL',
sourcemap: true,
globals: moduleGlobals
}
],
external: moduleExternals
}
// this version has three.js and everything else built in
const bundleConfig = {
input: 'src/ngl.ts',
plugins: [...plugins],
output: {
file: 'build/js/ngl.dev.js',
format: 'umd',
name: 'NGL',
sourcemap: true,
globals: {}
},
external: []
}
export default [
moduleConfig, bundleConfig
]