-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrollup.config.mjs
86 lines (78 loc) · 2.59 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import fs from 'fs/promises';
import path from 'path';
import url from 'url';
import rollupPluginBabel from '@rollup/plugin-babel';
import rollupPluginCommonJS from '@rollup/plugin-commonjs';
import rollupPluginNodeResolve from '@rollup/plugin-node-resolve';
import rollupPluginCopy from 'rollup-plugin-copy';
import rollupPluginDelete from 'rollup-plugin-delete';
import { minify as rollupPluginEsbuildMinify } from 'rollup-plugin-esbuild';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const extensions = ['.js', '.ts'];
const plugins = [
rollupPluginNodeResolve({ extensions }),
rollupPluginCommonJS(),
rollupPluginBabel({
babelHelpers: 'runtime',
compact: false,
extensions,
sourceMaps: true,
}),
];
export default (async () => {
const pkg = JSON.parse(await fs.readFile(path.join(__dirname, 'package.json')));
const { dependencies } = pkg;
const external = [
...Object.keys(dependencies || [])
.flatMap(name => [name, new RegExp(`^${ name }/`)]),
];
return [
{
plugins: [
...plugins,
rollupPluginDelete({
targets: ['lib/cjs/*', 'lib/esm/*'],
}),
],
input: 'src/index.ts',
output: [
{
dir: path.join(__dirname, 'lib', 'cjs'),
entryFileNames: '[name].js',
format: 'cjs',
preserveModules: true,
preserveModulesRoot: path.join(__dirname, 'src'),
sourcemap: true,
},
{
dir: path.join(__dirname, 'lib', 'esm'),
entryFileNames: '[name].mjs',
format: 'esm',
preserveModules: true,
preserveModulesRoot: path.join(__dirname, 'src'),
sourcemap: true,
},
],
external,
},
{
plugins: [
...plugins,
rollupPluginEsbuildMinify(),
rollupPluginDelete({
targets: ['dist/*'],
}),
rollupPluginCopy({
targets: [{ src: 'demo/public/*', dest: 'dist' }],
}),
],
input: 'demo/src/index.ts',
output: {
dir: path.join(__dirname, 'dist'),
entryFileNames: '[name].js',
format: 'iife',
sourcemap: true,
},
},
];
})();