-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathrollup.config.js
More file actions
84 lines (77 loc) · 2.34 KB
/
rollup.config.js
File metadata and controls
84 lines (77 loc) · 2.34 KB
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
import { dirname, join, relative, resolve } from 'node:path';
import { DEFAULT_EXTENSIONS as extensions } from '@babel/core';
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import preserveDirectives from 'rollup-preserve-directives';
import packageJson from './package.json' with { type: 'json' };
import tsBuildConfig from './tsconfig.build.json' with { type: 'json' };
const { outDir } = tsBuildConfig.compilerOptions;
const external = Object.keys(packageJson.peerDependencies);
export default defineConfig(
/** @satisfies {OutputOptions[]} */ ([
{
entryFileNames: '[name].cjs',
format: 'cjs',
},
{
entryFileNames: '[name].js',
format: 'esm',
},
]).map(
/**
* Rollup options for each module format
*
* @returns {RollupOptions}
*/
(options) => ({
input: 'src/index.ts',
output: [
{
...options,
dir: join(outDir, options.format),
preserveModules: true,
preserveModulesRoot: 'src',
sourcemap: true,
sourcemapExcludeSources: true,
// Fix source map relative paths to sources
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
const sourcePath = resolve(sourcemapPath, relativeSourcePath);
return relative(dirname(sourcemapPath), sourcePath);
},
},
],
external: ['react/jsx-runtime', ...external],
jsx: 'react-jsx',
treeshake: false,
plugins: [
nodeResolve({
browser: true,
}),
commonjs(),
typescript({
tsconfig: 'tsconfig.build.json',
compilerOptions: {
emitDeclarationOnly: true,
outDir: join(outDir, options.format),
},
}),
preserveDirectives(),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
extensions: [...extensions, '.ts', '.tsx'],
}),
],
// Handle warnings as errors
onwarn(warning) {
throw new Error(warning.message, { cause: warning });
},
}),
),
);
/**
* @import { OutputOptions, RollupOptions } from 'rollup'
*/