-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
96 lines (87 loc) · 2.21 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* eslint-disable import/no-default-export */
/* eslint-disable no-unused-vars */
import { getBabelInputPlugin } from '@rollup/plugin-babel'
import typescript from '@rollup/plugin-typescript'
import { defineConfig } from 'rollup'
import bundleSize from 'rollup-plugin-bundle-size'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
const TYPECHECK = true
const MINIFY = true
const src = (file) => `library/${file}`
const dist = (file) => `dist/${file}`
const bundle = (input, { plugins = [], ...config }) =>
defineConfig({
...config,
input,
plugins: plugins.filter(Boolean).concat(bundleSize()),
// do not bundle packages
external: (id) => !/^[./]/.test(id),
})
const config = defineConfig([
/* Compiled JS (CommonJS) */
bundle(src('index.ts'), {
plugins: [
TYPECHECK && typescript({ outputToFilesystem: false }),
esbuild(),
MINIFY && terser(),
],
output: [
{
file: pkg.main,
format: 'cjs',
},
],
}),
/* Compiled JS (ESM) */
bundle(src('index.ts'), {
plugins: [
TYPECHECK && typescript({ outputToFilesystem: false }),
getBabelInputPlugin({
babelrc: false,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
presets: ['@babel/preset-typescript', '@babel/preset-react'],
babelHelpers: 'bundled',
plugins: [
[
'module-resolver',
{
alias: {
'effector$': 'effector/effector.mjs',
'effector-react$': 'effector-react/effector-react.mjs',
'effector-react/scope$': 'effector-react/scope.mjs',
'next/router$': 'next/router.js',
},
},
],
],
}),
MINIFY && terser(),
],
output: [
{
file: pkg.module,
format: 'es',
},
],
}),
/* TS declarations */
bundle(src('index.ts'), {
plugins: [
dts({
compilerOptions: {
incremental: false,
},
}),
],
output: [
{
file: pkg.types,
format: 'es',
},
],
}),
])
export default config