-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.mjs
62 lines (59 loc) · 1.82 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
/*
* @Date: 2024-05-13 21:48:58
* @Description: Modify here please
*/
import glob from "fast-glob";
import { babel } from "@rollup/plugin-babel";
import typescript from "@rollup/plugin-typescript";
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import esbuild from "rollup-plugin-esbuild";
import { terser } from "rollup-plugin-terser";
import pkg from "./package.json" assert { type: "json" };
const files = glob.sync("**/*.{ts,tsx}", {
cwd: "./src",
absolute: true,
onlyFiles: true
});
const externalPackages = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})];
export default {
input: (() => {
const excludes = ["node_modules", "test", "dist", "style", "types"];
return files.filter((path) => !excludes.some((exclude) => path.includes(exclude)));
})(),
output: {
dir: "dist",
format: "esm",
sourcemap: true,
preserveModules: true,
preserveModulesRoot: "src"
},
plugins: [
nodeResolve({
extensions: [".js", ".jsx", ".ts", ".tsx"]
}),
commonjs(),
babel({
babelHelpers: "bundled",
presets: ["@babel/preset-env"],
extensions: [".js", ".jsx", ".ts", ".tsx", ".scss"],
exclude: "**/node_modules/**"
}),
esbuild({
// map compressed or converted code back to the original source code
sourceMap: true,
target: "es2018"
}),
typescript(),
terser({
mangle: false, // Disable variable name obfuscation
output: {
beautify: true, // Beautify output
comments: false // Delete all comments
}
})
],
// Creating regular expressions for the package to ensure that the subpath is also treated as external
external: externalPackages.map((packageName) => new RegExp(`^${packageName}(/.*)?`)),
treeshake: false
};