-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
72 lines (65 loc) · 1.89 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
const babel = require('@rollup/plugin-babel').default;
const commonjs = require('@rollup/plugin-commonjs').default;
const resolve = require('@rollup/plugin-node-resolve').default;
const { dts } = require('rollup-plugin-dts');
const packageJson = require('./package.json');
const json = require('@rollup/plugin-json').default;
const { author, dependencies, devDependencies, name, version } = packageJson;
const external = [...Object.keys(dependencies), ...Object.keys(devDependencies)].filter(
(pkgName) => !['p-limit', 'deepmerge-ts', 'hexo-is', 'is-stream', 'markdown-it'].includes(pkgName)
);
const banner = `// ${name} ${version} by ${author.name} <${author.email}> (${author.url})`.trim();
const esmBanner = `
${banner}
import nodeUrl from 'node:url';
import nodePath from 'path';
const __filename = nodeUrl.fileURLToPath(import.meta.url);
const __dirname = nodePath.dirname(__filename);
`.trim();
/**
* @type {import('rollup').RollupOptions}
*/
const libs = {
input: './tmp/dist/src/index.js',
output: [
{
file: 'dist/index.js',
format: 'cjs',
exports: 'named',
banner
},
{
file: 'dist/index.cjs',
format: 'cjs',
exports: 'named',
banner
},
{
file: 'dist/index.mjs',
format: 'esm',
exports: 'named',
banner: esmBanner
}
],
external,
plugins: [
json(),
resolve({ preferBuiltins: true }),
commonjs(),
babel({ babelHelpers: 'bundled', exclude: 'node_modules/**' })
]
};
/**
* @type {import('rollup').RollupOptions}
*/
const declaration = {
input: './tmp/dist/src/index.d.ts',
output: [
{ file: 'dist/index.d.ts', format: 'es', exports: 'named' },
{ file: 'dist/index.d.mts', format: 'es', exports: 'named' },
{ file: 'dist/index.d.cts', format: 'es', exports: 'named' }
],
plugins: [resolve({ preferBuiltins: true }), dts()],
external
};
module.exports = [libs, declaration];