-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathrollup.config.mjs
64 lines (60 loc) · 1.64 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
63
64
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import { defineConfig } from 'rollup';
import typescript from 'rollup-plugin-typescript2';
import external from 'rollup-plugin-peer-deps-external';
import json from '@rollup/plugin-json';
import dts from 'rollup-plugin-dts';
import alias from '@rollup/plugin-alias';
import fs from 'fs';
import path from 'path';
import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const absolute = _path => path.resolve(__dirname, _path);
const entries = {
'@/types': absolute('src/types/index.ts'),
'@/abi': absolute('src/abi/index.ts'),
'@/exceptions': absolute('src/exceptions/index.ts'),
'@/http': absolute('src/http/index.ts'),
'@/common': absolute('src/common/index.ts'),
};
export default defineConfig([
{
input: {
index: 'src/index.ts',
},
output: [
{
entryFileNames: 'index.esm.js',
format: 'esm',
dir: 'dist',
},
{
entryFileNames: 'index.js',
format: 'cjs',
dir: 'dist',
},
],
plugins: [
json(),
alias({ entries }),
external(),
commonjs(),
nodeResolve({}),
typescript({ tsconfig: 'tsconfig.build.json', useTsconfigDeclarationDir: true, exclude: ['__test__'] }),
],
context: 'globalThis',
},
{
input: 'dist/src/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [alias({ entries }), dts(), clearTargetPlugin()],
},
]);
function clearTargetPlugin() {
return {
buildEnd() {
fs.rmSync('dist/src', { recursive: true });
},
};
}