-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (32 loc) · 981 Bytes
/
index.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
const requireFile = require("shaderity-node").requireFile;
const getShaderStage = require("shaderity-node").shaderStage;
const path = require('path');
const fs = require('fs');
module.exports = options => {
return {
name: 'shaderity',
setup (build) {
build.onResolve({ filter: /\.(glsl|vs|fs|vert|frag)$/ }, (args) => {
return {
path: path.resolve(args.resolveDir, args.path),
namespace: 'shaderity'
}
});
build.onLoad({ filter: /.*/, namespace: 'shaderity' }, (args) => {
const source = fs.readFileSync(args.path, 'utf-8')
const code = requireFile(source, args.path)
const shaderStage = getShaderStage(args.path)
const isFragmentShader = shaderStage === 'fragment'
const json = {
code,
shaderStage,
isFragmentShader,
};
return {
contents: JSON.stringify(json),
loader: 'json'
}
});
}
}
}