forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
97 lines (90 loc) · 2.27 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
//@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";
const pkg = JSON.parse(
fs
.readFileSync(
path.join(path.dirname(fileURLToPath(import.meta.url)), "package.json")
)
.toString()
);
// 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",
"react-onclickoutside": "onClickOutside",
classnames: "classNames",
};
// NOTE:https://rollupjs.org/migration/#changed-defaults
const migrateRollup2to3OutputOptions = {
interop: "compat",
};
const config = {
input: "src/index.jsx",
output: [
{
file: pkg.browser,
format: "umd",
name: "DatePicker",
globals,
...migrateRollup2to3OutputOptions,
},
{
file: "dist/react-datepicker.js",
format: "umd",
name: "DatePicker",
globals,
...migrateRollup2to3OutputOptions,
},
{
file: pkg.main,
format: "cjs",
name: "DatePicker",
...migrateRollup2to3OutputOptions,
},
{
file: pkg.module,
format: "es",
...migrateRollup2to3OutputOptions,
},
],
plugins: [
resolve({
mainFields: ["module"],
extensions: [".js", ".jsx"],
}),
babel(),
commonjs(),
filesize(),
terser(),
],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...dateFnsSubpackages,
],
};
export default config;