forked from vultix/ts-results
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
81 lines (74 loc) · 1.79 KB
/
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
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
77
78
79
80
81
import path from 'path';
import typescript from '@rollup/plugin-typescript';
import pkg from './package.json'
// Gather external modules
const external = [
// All dependencies are external
...Object.keys(pkg.dependencies ?? []),
...Object.keys(pkg.devDependencies ?? []),
'rxjs/operators/index.js',
];
const banner = `/**
* ${pkg.name} v${pkg.version}
* Author: ${pkg.author}
* LICENSE: ${pkg.license}
*
* ${pkg.repository.url}
*/
`;
const defaultConfig = {
input: {
index: path.join(__dirname, 'src', 'index.ts'),
"rxjs-operators/index": path.join(__dirname, 'src', 'rxjs-operators', 'index.ts')
},
output: {
name: pkg.name,
preserveModules: true,
banner,
},
external,
onwarn(warning, warn) {
// Throw an error on unresolved dependencies (not listed in package json)
if (warning.code === 'UNRESOLVED_IMPORT')
throw new Error(`${warning.message}.
Make sure this dependency is listed in the package.json
`);
// Use default for everything else
warn(warning);
},
plugins: [
typescript({
noEmitOnError: false,
sourceMap: false,
}),
],
};
const cjsConfig = {
...defaultConfig,
output: {
...defaultConfig.output,
dir: path.dirname(pkg.main),
format: 'cjs',
entryFileNames: "[name].js",
}
};
const esmConfig = {
...defaultConfig,
output: {
...defaultConfig.output,
dir: path.dirname(pkg.module),
format: 'esm',
entryFileNames: "[name].mjs",
},
plugins: [
typescript({
noEmitOnError: false,
sourceMap: false,
outDir: path.dirname(pkg.module),
}),
],
};
export default [
cjsConfig,
esmConfig,
];