-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.js
104 lines (93 loc) · 2.98 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
let rf = require('fs');
let path = require('path');
let replace = require('rollup-plugin-replace');
let uglify = require('rollup-plugin-uglify');
function glsl(shaderurl) {
if(shaderurl.charAt(shaderurl.length)=='/') shaderurl = shaderurl.substr(0,shaderurl.length-1);
function compile(code,filelist,current){
let state = 0,include='',url='',temp='';
for(let c of code){
switch (c){
case ';':
case '{':
case '}':
state = 0;
temp += c;
break;
case '#':
state = 1;
include+='#';
break;
case `"`:
if(state==9) state = 10;
else if(state==10) {
state = 0;
url = path.normalize(current+'/'+url);
if(!filelist.includes(url)){
filelist.push(url);
temp += compile(rf.readFileSync(shaderurl+'/'+url,"utf-8"),filelist,path.dirname(url));
}
url='';
}else temp += c;
break;
default:
if(state == 8){
if(include == '#include') state=9;
else {
state = 0;
temp += include + c;
}
include = '';
}else if(state > 0&&state < 8) {
include += c;
state++;
}else if(state == 10) url += c;
else if(state == 0) temp += c;
}
}
return temp;
}
return {
transform( code, id ) {
let reg = new RegExp(`${shaderurl}\/(.*?glsl)$`);
let result = reg.exec( id );
if ( !result ) return;
//let url = path.normalize(result[1]);
//code = compile(code,[url],path.dirname(url));
let transformedCode = 'export default ' + JSON.stringify(
code.replace( /[ \t]*\/\/.*\n/g, '' ) // remove //
.replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' ) // remove /* */
.replace( /\n{2,}/g, '\n' ) // # \n+ to \n
) + ';';
return {
code: transformedCode,
map: { mappings: '' }
};
}
};
}
export default {
input: 'index.js',
plugins: [
glsl('src/shader'),
replace({
MAXVALUE:1e5,
MINVALUE:1e-4
}),
//uglify(),
],
// sourceMap: true,
output: [
{
format: 'umd',
name: 'Sail',
file: 'bin/sail.js',
indent: '\t'
},
{
format: 'es',
file: 'bin/sail.module.js',
indent: '\t'
}
]
};