forked from HoudiniGraphql/houdini
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
47 lines (43 loc) · 1.26 KB
/
rollup.config.js
File metadata and controls
47 lines (43 loc) · 1.26 KB
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
import typescript from 'rollup-plugin-typescript2'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import replace from '@rollup/plugin-replace'
import packgeJSON from './package.json'
// grab the environment variables
const { TARGET, WHICH } = process.env
// use the correct source file
const input = WHICH === 'cmd' ? 'src/cmd/main.ts' : `src/${WHICH}/index.ts`
const out = {
cmd: {
file: 'build/cmd.js',
exports: 'named',
banner: '#! /usr/bin/env node',
},
preprocess: {
dir: `build/${WHICH.toLowerCase()}-${TARGET.toLowerCase()}`,
exports: process.env.TARGET === 'cjs' ? 'default' : undefined,
},
}[WHICH]
// we need to use rollup to handle esm/cjs interop.
// this is primarily because esm forces us to specify the filepath of our imports.
// typescript supports importing .ts files as .js but jest isn't happy.
export default {
input,
output: {
format: TARGET === 'esm' ? 'esm' : 'cjs',
...out,
},
external: ['graphql', './adapter.mjs', '$houdini'],
plugins: [
json(),
typescript({
declarationDir: `build/${WHICH}-${TARGET}`,
}),
commonjs(),
nodeResolve({ preferBuiltins: true }),
replace({
HOUDINI_VERSION: packgeJSON.version,
}),
],
}