-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
executable file
·83 lines (80 loc) · 2.17 KB
/
rollup.config.mjs
File metadata and controls
executable file
·83 lines (80 loc) · 2.17 KB
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
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import { dts } from "rollup-plugin-dts";
import terser from "@rollup/plugin-terser";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import pkg from "./package.json" assert { type: "json" };
import analyze from "rollup-plugin-analyzer";
import { visualizer } from "rollup-plugin-visualizer";
const isProduction = process.env.NODE_ENV === "production";
const externalDeps = Object.keys(pkg.peerDependencies || {});
const createConfig = (input, output) => ({
input,
output: [
{
file: output.cjs,
format: "cjs",
sourcemap: true,
},
{
file: output.esm,
format: "esm",
sourcemap: true,
},
],
external: [...externalDeps, ...output.externalLibs],
onwarn(warning, warn) {
if (
warning.code === "MODULE_LEVEL_DIRECTIVE" &&
warning.message.includes('"use client"')
)
return;
warn(warning);
},
plugins: [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({
tsconfig: "./tsconfig.json",
exclude: ["**/*.test.tsx", "**/*.test.ts", "**/*stories.tsx"],
}),
postcss({
minimize: isProduction,
extract: true,
}),
isProduction && terser(),
analyze({ summaryOnly: true }),
visualizer({
filename: output.analysis,
open: false,
}),
],
});
export default [
createConfig("src/index.ts", {
cjs: pkg.main,
esm: pkg.module,
analysis: "bundle-analysis-main.html",
externalLibs: ["react/jsx-runtime"],
}),
createConfig("src/PDFViewerCanvas.ts", {
cjs: "dist/PDFViewerCanvas.cjs.js",
esm: "dist/PDFViewerCanvas.esm.js",
analysis: "bundle-analysis-pdfvc.html",
externalLibs: ["pdfjs-dist/webpack.mjs", "pdfjs-dist"],
}),
{
input: "src/index.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
external: [/\.css$/, /\.scss$/],
plugins: [dts()],
},
{
input: "src/PDFViewerCanvas.ts",
output: [{ file: "dist/PDFViewerCanvas.d.ts", format: "esm" }],
plugins: [dts()],
},
];