-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (54 loc) · 1.66 KB
/
main.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
const fs = require('fs');
const { spglslAngleCompile } = require('spglsl');
const convertError = (e) => ({
text: e.toString(),
location: {
file: e.filePath,
line: e.line,
column: 0,
lineText: e.source,
},
});
module.exports = ({
compileMode = 'Optimize',
minify = false,
mangle = false,
mangle_global_map
} = {}) => ({
name: 'spglsl',
setup(build) {
build.onLoad(
{ filter: /\.(?:frag|vert|glsl)$/ },
async (args) => {
const contents = await fs.promises.readFile(args.path, 'utf8');
const errors = [];
const warnings = [];
const result = await spglslAngleCompile({
mainFilePath: args.path,
mainSourceCode: contents,
compileMode,
minify,
mangle,
mangle_global_map,
});
if (!result.valid) {
result.infoLog.forEach((e) => {
if (e.type === 'ERROR' || e.type === 'UNKNOWN ERROR') {
errors.push(convertError(e));
}
else if (e.type === 'WARNING') {
warnings.push(convertError(e));
}
})
}
if (errors.length > 0 || warnings.length > 0) {
return { errors, warnings };
}
return {
contents: result.output,
loader: 'text',
}
},
);
},
});