-
Notifications
You must be signed in to change notification settings - Fork 13
/
rollup.config.js
39 lines (36 loc) · 972 Bytes
/
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
import ts from '@rollup/plugin-typescript';
import { promises as fs } from 'fs';
const isCJSBuild = process.env.MODE === 'cjs';
const commonjsPkgJSONPlugin = () => {
return {
name: 'commonjsPkgJSONPlugin',
writeBundle: async () => {
if (isCJSBuild === true) {
await fs.writeFile(
'dist/cjs/package.json',
JSON.stringify({
type: 'commonjs',
})
);
} else {
await fs.copyFile('package.json', 'dist/package.json');
await fs.copyFile('README.md', 'dist/README.md');
}
},
};
};
export default {
input: ['src/index.ts', 'src/relay.ts'],
output: [
{
dir: isCJSBuild ? 'dist/cjs' : 'dist',
format: isCJSBuild ? 'cjs' : 'esm',
entryFileNames: isCJSBuild ? '[name].cjs' : '[name].js',
},
],
plugins: [
ts({ tsconfig: isCJSBuild ? 'tsconfig.cjs.json' : 'tsconfig.json' }),
commonjsPkgJSONPlugin(),
],
external: ['graphql'],
};