-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.ts
76 lines (72 loc) · 1.97 KB
/
rollup.config.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
import fs from 'node:fs';
import url from 'node:url';
import path from 'node:path';
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import multi from 'rollup-plugin-multi-input';
import terser from '@rollup/plugin-terser';
const isProduction = process.env.NODE_ENV === 'production';
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
const extensions = ['.js', '.ts'];
export const createPackageJSON = (dir = 'esm', type = 'module') => ({
name: 'create-package-json',
writeBundle: () => fs.promises.writeFile(
path.join(dirname, 'dist', dir, 'package.json'),
JSON.stringify({ type }, null, 4),
'utf-8'
)
});
const esm = {
input: [
'src/tangle.ts',
'src/worker_threads.ts',
'src/webviews.ts',
'src/webworkers.ts',
'src/iframes.ts'
],
output: {
format: 'esm',
dir: 'dist/esm',
exports: 'auto',
sourcemap: !isProduction,
...(isProduction
? { plugins: [terser()] }
: {}
)
},
plugins: [
multi.default(),
resolve({ extensions }),
typescript({
tsconfig: './tsconfig.json',
outDir: 'dist/esm',
declaration: true,
declarationDir: './dist/esm',
sourceMap: !isProduction
}),
createPackageJSON(),
cleanup({ comments: 'none' })
],
};
const cjs = {
...esm,
output: {
...esm.output,
format: 'cjs',
dir: 'dist/cjs'
},
plugins: [
...esm.plugins.slice(0, 2),
typescript({
tsconfig: './tsconfig.json',
outDir: 'dist/cjs',
declaration: true,
declarationDir: './dist/cjs',
sourceMap: !isProduction
}),
createPackageJSON('cjs', 'commonjs'),
...esm.plugins.slice(4)
]
};
export default [ cjs, esm ];