-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
98 lines (96 loc) · 2.64 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
// rollup.config.js
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import postcss from "rollup-plugin-postcss";
import url from "@rollup/plugin-url";
import { babel } from "@rollup/plugin-babel";
import alias from "@rollup/plugin-alias";
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
import path from "path";
import { fileURLToPath } from "url";
import { terser } from "rollup-plugin-terser";
import analyze from "rollup-plugin-analyzer";
// Get the directory name of the current module
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default {
input: "src/index.tsx",
output: [
{
format: "esm",
dir: "dist/esm",
entryFileNames: "index.js",
sourcemap: true,
plugins: [terser()],
},
],
plugins: [
alias({
entries: [
{ find: "src", replacement: path.resolve(__dirname, "./src") },
{ find: "app", replacement: path.resolve(__dirname, "./src/app") },
{
find: "components",
replacement: path.resolve(__dirname, "./src/components"),
},
{
find: "services",
replacement: path.resolve(__dirname, "./src/services"),
},
{
find: "hocs",
replacement: path.resolve(__dirname, "./src/hocs"),
},
{
find: "helpers",
replacement: path.resolve(__dirname, "./src/helpers"),
},
],
}),
peerDepsExternal(),
resolve({
preferBuiltins: false,
browser: true,
}),
commonjs(),
json(),
typescript({
tsconfig: "./tsconfig.json",
useTsconfigDeclarationDir: true,
clean: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationDir: "./dist/types",
emitDeclarationOnly: true,
},
},
}),
postcss({
// extract: "index.css", // Extract CSS to the root dist directory
minimize: true,
inject: true,
}),
url({
include: ["**/*.svg"],
limit: 8192,
emitFiles: true,
}),
babel({
babelHelpers: "bundled",
presets: ["@babel/preset-react", "@babel/preset-typescript"],
extensions: [".js", ".jsx", ".ts", ".tsx"],
}),
replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify("production"),
"use client": "",
}),
terser(),
analyze({ summaryOnly: true }),
],
external: ["react", "react-dom"],
};