-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
rollup.config.ts
90 lines (84 loc) · 2.03 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {readFileSync} from 'fs';
import * as path from 'path';
import {RollupOptions} from 'rollup';
import {babel, RollupBabelInputPluginOptions} from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import includePaths from 'rollup-plugin-includepaths';
import cleanupPlugin from 'rollup-plugin-cleanup';
const packageJSON = readFileSync(
new URL('./package.json', import.meta.url).pathname,
) as unknown;
const pkg = JSON.parse(packageJSON as string);
const extensions = ['.js', '.ts'];
export function generateConfig({
output,
targets,
}: {
output: RollupOptions['output'];
targets: RollupBabelInputPluginOptions['targets'];
}): RollupOptions {
return {
input: './src/index',
plugins: [
includePaths({
include: {
shared: 'src/shared',
},
paths: ['src/'],
extensions: [...extensions],
}),
nodeResolve({extensions: [...extensions]}),
commonjs(),
babel({
extensions,
exclude: 'node_modules/**',
babelHelpers: 'bundled',
envName: 'production',
targets,
}),
cleanupPlugin({
extensions: [...extensions],
maxEmptyLines: 1,
}),
],
output,
};
}
const config = [
generateConfig({
targets: [...pkg.browserslist],
output: [
{
format: 'cjs',
dir: path.dirname(pkg.main),
preserveModules: true,
entryFileNames: '[name].cjs',
exports: 'named',
},
{
format: 'esm',
dir: path.dirname(pkg.module),
preserveModules: true,
entryFileNames: '[name].mjs',
},
{
format: 'umd',
dir: path.dirname(pkg.umd),
name: 'Draggable',
},
],
}),
generateConfig({
targets: 'last 1 chrome versions',
output: [
{
format: 'esm',
dir: path.dirname(pkg.esnext),
preserveModules: true,
entryFileNames: '[name].mjs',
},
],
}),
];
export default config;