forked from rollup/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (35 loc) · 908 Bytes
/
Copy pathindex.js
File metadata and controls
41 lines (35 loc) · 908 Bytes
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
import { createFilter } from '@rollup/pluginutils';
import loader from 'graphql-tag/loader.js';
import { toESModules } from './toESModules';
export default function graphql({ include, exclude } = {}) {
// path filter
const filter = createFilter(include, exclude);
// only .graphql, .graphqls (schema), and .gql files
const filterExt = /\.(graphqls?|gql)$/i;
return {
name: 'graphql',
transform: {
filter: {
id: filterExt
},
handler(source, id) {
if (!filter(id)) return null;
if (!filterExt.test(id)) return null;
// XXX: this.cachable() in graphql-tag/loader
const code = toESModules(
loader.call(
{
cacheable() {}
},
source
)
);
const map = { mappings: '' };
return {
code,
map
};
}
}
};
}