-
Notifications
You must be signed in to change notification settings - Fork 179
/
rollup.config.mjs
62 lines (58 loc) · 1.77 KB
/
rollup.config.mjs
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
61
62
import typescript from '@rollup/plugin-typescript';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import {join} from 'path';
const srcDir = join(__dirname, 'src');
const outDir = 'output';
/**
* Builds a rollup config for esm or cjs
*
* @type {(format: 'cjs' | 'esm') => import('rollup').RollupOptions}
*/
function buildConfig(format) {
return {
//external: ['zod', 'lodash.transform', 'events', 'uuid'],
input: 'src/index.ts',
output: {
dir: outDir,
format,
name: 'DiscordSDK',
preserveModules: true,
exports: 'named',
entryFileNames(chunk) {
const ext = format == 'cjs' ? 'cjs' : 'mjs';
// Flatten src dir so output is `output/index.js`
// instead of `ouput/src/index.js`.
if (chunk.facadeModuleId.startsWith(srcDir)) {
const name = chunk.name.replace(/^src\//, '');
return `${name}.${ext}`;
}
// Since node modules are bundled, renamed the output
// directory so it doesn't clash with node_modules semantics.
if (chunk.facadeModuleId.includes('node_modules/')) {
const name = chunk.name
.replaceAll('node_modules/', 'lib/')
// Also remove the .npm prefix if present
.replace('.npm/', '');
return `${name}.${ext}`;
}
return `[name].${ext}`;
},
},
plugins: [
// i dont want to include the node modules
// but it's causing issues
nodeResolve({
preferBuiltins: false,
}),
commonjs(),
typescript({
declaration: true,
outDir: outDir,
}),
json(),
],
};
}
export default [buildConfig('cjs'), buildConfig('esm')];