-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
rollup.config.mjs
116 lines (108 loc) · 2.75 KB
/
rollup.config.mjs
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
//@ts-check
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import babel from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import filesize from "rollup-plugin-filesize";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
const pkg = JSON.parse(
fs
.readFileSync(
path.join(path.dirname(fileURLToPath(import.meta.url)), "package.json"),
)
.toString(),
);
const banner = `/*!
${pkg.name} v${pkg.version}
${pkg.homepage}
Released under the ${pkg.license} License.
*/`;
// it's important to mark all subpackages of data-fns as externals
// see https://github.com/Hacker0x01/react-datepicker/issues/1606
// We're relying on date-fn's package.json `exports` field to
// determine the list of directories to include.
const dateFnsPackageJson = JSON.parse(
fs
.readFileSync(
path.join(
path.dirname(fileURLToPath(import.meta.url)),
"node_modules/date-fns/package.json",
),
)
.toString(),
);
const dateFnsSubpackages = Object.keys(dateFnsPackageJson.exports)
.map((key) => key.replace("./", ""))
.filter((key) => key !== "." && key !== "package.json")
.map((key) => `date-fns/${key}`);
const globals = {
react: "React",
"prop-types": "PropTypes",
};
// NOTE:https://rollupjs.org/migration/#changed-defaults
/** @type {import('rollup').OutputOptions} */
const migrateRollup2to3OutputOptions = {
interop: "compat",
};
/** @type {import('rollup').RollupOptions} */
const config = {
input: "src/index.tsx",
output: [
{
file: pkg.browser,
format: "umd",
name: "DatePicker",
globals,
banner,
...migrateRollup2to3OutputOptions,
plugins: [terser()],
},
{
file: pkg.browser.replace(".min.js", ".js"),
format: "umd",
sourcemap: "inline",
name: "DatePicker",
globals,
banner,
...migrateRollup2to3OutputOptions,
},
{
file: pkg.main,
format: "cjs",
sourcemap: "inline",
name: "DatePicker",
banner,
...migrateRollup2to3OutputOptions,
},
{
file: pkg.module,
format: "es",
sourcemap: "inline",
banner,
...migrateRollup2to3OutputOptions,
},
],
plugins: [
resolve({
mainFields: ["module"],
extensions: [".js", ".jsx", ".ts", ".tsx"],
}),
babel(),
commonjs(),
typescript({
tsconfig: "./tsconfig.build.json",
declaration: true,
declarationDir: "dist",
}),
filesize(),
],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...dateFnsSubpackages,
],
};
export default config;