-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
145 lines (142 loc) · 3.22 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* rollup.config.js - Rollup configuration.
* Copyright (c) 2019 - 2021 Richard Huang <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import babel from '@rollup/plugin-babel';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import fs from 'fs';
import path from 'path';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const banner = `/*! ${pkg.name} v${pkg.version} | (c) ${pkg.author.name} <${pkg.author.email}> | ${pkg.license} */`;
const external = [
'react',
'react/jsx-runtime',
];
const globals = {
react: 'React',
'react/jsx-runtime': 'jsxRuntime',
};
const input = ['./src/index.js'];
const writePackage = (json, to) => ({
generateBundle() {
const {
devDependencies,
eslintConfig,
jest,
optionalDependencies,
scripts,
...output
} = json;
// Short circuit with assignment above.
delete output.babel;
fs.writeFileSync(path.resolve(to), JSON.stringify(output));
},
name: 'write-package',
});
export default [
// CJS and ESM.
{
external,
input,
onwarn: (warning, next) => {
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return;
next(warning);
},
output: [
{
banner,
exports: 'named',
file: `dist/${pkg.main}`,
format: 'cjs',
globals,
sourcemap: true,
strict: false,
},
{
banner,
exports: 'named',
file: `dist/${pkg.module}`,
format: 'esm',
globals,
sourcemap: true,
strict: false,
},
],
plugins: [
// Begin run once.
del({
targets: 'dist/*',
}),
copy({
targets: [
{ src: ['CHANGELOG.md', 'example.js', 'LICENSE', 'README.md'], dest: 'dist' },
],
}),
writePackage(pkg, 'dist/package.json'),
// End run once.
babel({
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [
'@babel/flow',
[
'@babel/react',
{
runtime: 'automatic',
},
],
],
}),
terser({
compress: false,
mangle: false,
}),
],
},
// UMD.
{
external,
input,
output: [
{
banner,
esModule: false,
exports: 'named',
file: 'dist/index.umd.js',
format: 'umd',
globals,
name: 'reactStoreContextHooks',
sourcemap: true,
},
],
plugins: [
babel({
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [
[
'@babel/preset-env',
{
exclude: ['transform-typeof-symbol'],
targets: {
browsers: [
'last 2 versions',
'> 5%',
],
},
},
],
'@babel/flow',
'@babel/react',
],
}),
terser(),
],
},
];