forked from rtk-incubator/rtk-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
101 lines (95 loc) · 2.73 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
97
98
99
100
101
import babel from '@rollup/plugin-babel';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
/** @type {import("rollup").RollupOptions} */
const defaultConfig = {
input: ['src/index.ts', 'src/react.ts'],
external: [/@babel\/runtime/, /@reduxjs\/toolkit/, /react$/, /react-redux/, /immer/, /tslib/],
treeshake: {
propertyReadSideEffects: false,
moduleSideEffects: false,
},
};
const defaultTerserOptions = {
output: { comments: false },
compress: {
keep_infinity: true,
pure_getters: true,
passes: 10,
},
ecma: 5,
warnings: true,
};
const defaultTsConfig = { declaration: false, declarationMap: false, target: 'ESNext', module: 'esnext' };
/** @type {import("rollup").RollupOptions} */
const configs = [
// ESM
{
...defaultConfig,
output: [
{
dir: 'dist/esm',
format: 'es',
sourcemap: true,
preserveModules: true,
},
],
plugins: [
typescript({ ...defaultTsConfig, declarationDir: 'dist/esm/ts', declaration: true, declarationMap: true }),
babel({
exclude: 'node_modules/**',
extensions: ['.js', '.ts'],
babelHelpers: 'runtime',
presets: [
[
'@babel/preset-env',
{
targets: { node: true, browsers: ['defaults', 'not IE 11', 'maintained node versions'] },
bugfixes: true,
loose: true,
},
],
],
plugins: [['@babel/plugin-transform-runtime', { useESModules: true }]],
}),
],
},
// CJS:
...[].concat(
...defaultConfig.input.map((input) =>
withMinify((minified) => ({
...defaultConfig,
input,
output: [
{
dir: 'dist',
format: 'cjs',
sourcemap: true,
entryFileNames: minified ? '[name].cjs.production.min.js' : '[name].cjs.development.js',
},
],
plugins: [
typescript(defaultTsConfig),
replace({
values: {
'process.env.NODE_ENV': JSON.stringify(minified ? 'production' : 'development'),
},
}),
babel({
exclude: 'node_modules/**',
extensions: ['.js', '.ts'],
babelHelpers: 'runtime',
presets: [['@babel/preset-env', { targets: { node: true, browsers: ['defaults'] } }]],
plugins: [['@babel/plugin-transform-runtime', { useESModules: false }]],
}),
...(minified ? [terser({ ...defaultTerserOptions, toplevel: true })] : []),
],
}))
)
),
];
function withMinify(build) {
return [build(false), build(true)];
}
export default configs;