-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.ts
More file actions
70 lines (62 loc) · 2.02 KB
/
rollup.config.ts
File metadata and controls
70 lines (62 loc) · 2.02 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
import { resolve } from "node:path";
import { RollupOptions } from "rollup";
import ts from "typescript";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { babel } from "@rollup/plugin-babel";
import terser from "@rollup/plugin-terser";
import pkg from "./package.json" assert { type: "json" };
const external = Object.keys(pkg.peerDependencies);
const isExternal = (moduleId: string) =>
external.includes(moduleId) || external.some((e) => moduleId.startsWith(e));
const extensions = [".js", ".jsx", ".ts", ".tsx"];
const babelTargets = "last 2 years";
const input = "src/index.ts";
const config: RollupOptions = {
input: input,
output: [
{
file: pkg.module,
format: "esm",
sourcemap: true,
},
{
file: pkg.main,
format: "cjs",
sourcemap: true,
},
],
external: isExternal,
plugins: [
babel({
extensions,
babelHelpers: "bundled",
presets: [
["babel-preset-solid", {}],
"@babel/preset-typescript",
["@babel/preset-env", { bugfixes: true, targets: babelTargets }],
],
}),
nodeResolve({ extensions }),
terser(),
{
name: "ts",
buildEnd() {
const program = ts.createProgram([resolve("src/index.ts")], {
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.Node10,
jsx: ts.JsxEmit.Preserve,
jsxImportSource: "solid-js",
allowSyntheticDefaultImports: true,
esModuleInterop: true,
outDir: `dist/source`,
declarationDir: `dist/types`,
declaration: true,
allowJs: true,
});
program.emit();
},
},
],
};
export default config;