-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
207 lines (192 loc) · 4.88 KB
/
Copy pathtsdown.config.ts
File metadata and controls
207 lines (192 loc) · 4.88 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { defineConfig, type UserConfig } from "tsdown";
import strip from "vite-plugin-strip-comments";
import { readFile, rename, writeFile } from "fs/promises";
import { join } from "node:path";
const pkg = await import("./package.json", { with: { type: "json" } }).then(
(m) => m.default,
);
const year = new Date().getFullYear();
const banner = `/*!
* @thednp/tween $package v${pkg.version} (${pkg.homepage})
* Copyright ${year} © ${pkg.author}
* Licensed under MIT (https://github.com/thednp/tween/blob/master/LICENSE)
*/
"use strict";
`;
const miniBanner = `/*! @thednp/tween $package v${pkg.version} | ${pkg.author} © ${year} | ${pkg.license}-License */
"use strict";`;
const baseConfig: UserConfig = {
deps: {
skipNodeModulesBundle: true,
neverBundle: [
"rolldown",
"vite",
"solid-js",
"react",
"svelte",
"vue",
"@thednp/tween",
"preact",
"svg-path-commander",
"svg-path-commander/util",
"@thednp/dommatrix",
"@preact/signals",
"vanjs-core",
],
},
target: "esnext",
exports: true,
format: ["esm"],
// dts: true,
dts: {
sourcemap: true,
sideEffects: false,
},
sourcemap: true,
// skipNodeModulesBundle: true,
globalName: "TWEEN",
plugins: [strip({ type: "keep-jsdoc" })],
};
const renameSvelteJSON = async () => {
const pkgJSON = JSON.parse(await readFile("package.json", "utf8"));
pkgJSON.exports["./svelte"] = pkgJSON.exports["./svelte"].replace(
"svelte.mjs",
"tween.svelte.js",
);
await writeFile("package.json", JSON.stringify(pkgJSON, null, 2));
console.log("✔ package.json updated");
};
const renameSvelteFiles = () => ({
name: "rename-svelte-files",
apply: "after",
async closeBundle() {
const outDir = /*options.dir ||*/ "dist/svelte";
const renames = [
{ from: "svelte.mjs", to: "tween.svelte.js" },
{ from: "svelte.d.mts", to: "tween.svelte.d.ts" },
// { from: "svelte.cjs", to: "tween.svelte.cjs" },
// { from: "svelte.mjs.map", to: "index.svelte.mts" },
// Add .map if sourcemap: true
];
const callback = async () => {
for (const { from, to } of renames) {
const fromPath = join(outDir, from);
const toPath = join(outDir, to);
try {
await rename(fromPath, toPath);
console.log(`✔ Renamed: ${from} → ${to}`);
} catch (e) {
if ((e as { code: string })?.code !== "ENOENT")
console.error(`Rename failed: ${from}`, e);
}
}
await renameSvelteJSON();
};
setTimeout(callback, 150);
},
});
export default defineConfig([
// Core tween
{
...baseConfig,
clean: true,
banner: banner.replace("$package", ""),
// skipNodeModulesBundle: true,
entry: {
index: "src/index.ts",
},
outDir: "dist/tween",
},
// Core tween UMD
{
...baseConfig,
exports: false,
minify: true,
format: "umd",
globalName: "TWEEN",
deps: {
skipNodeModulesBundle: false,
alwaysBundle: ["svg-path-commander", "svg-path-commander/util"],
},
// noExternal: ["svg-path-commander", "svg-path-commander/util"],
banner: miniBanner.replace("$package", "UMD"),
target: "esnext",
entry: {
index: "src/index.ts",
},
// outDir: "dist",
outputOptions: {
// dir: "dist",
codeSplitting: false,
file: "dist/tween.min.js",
},
},
// React
{
...baseConfig,
banner: banner.replace("$package", "hooks for React"),
entry: {
react: "src/react/index.ts",
},
// skipNodeModulesBundle: true,
outDir: "dist/react",
},
// Preact
{
...baseConfig,
banner: banner.replace("$package", "hooks for Preact"),
entry: {
preact: "src/preact/index.ts",
},
// skipNodeModulesBundle: true,
outDir: "dist/preact",
},
// Solid
{
...baseConfig,
banner: banner.replace("$package", "primitives for SolidJS"),
entry: {
solid: "src/solid/index.ts",
},
// skipNodeModulesBundle: true,
outDir: "dist/solid",
},
// Vue
{
...baseConfig,
banner: banner.replace("$package", "composables for Vue"),
entry: {
vue: "src/vue/index.ts",
},
// skipNodeModulesBundle: true,
outDir: "dist/vue",
},
// VanJS
{
...baseConfig,
banner: banner.replace("$package", "primitives for VanJS"),
entry: {
vanjs: "src/vanjs/index.ts",
},
outDir: "dist/vanjs",
},
// Svelte
{
...baseConfig,
target: "es2023",
banner: banner.replace("$package", "utils for Svelte"),
entry: {
svelte: "src/svelte/index.svelte.ts",
},
// skipNodeModulesBundle: true,
plugins: [renameSvelteFiles()],
outDir: "dist/svelte",
// not working...
// outputOptions: {
// codeSplitting: false,
// // dir: "dist/svelte",
// file: "dist/svelte/tween.svelte.js",
// // file: "tween.svelte.js",
// },
},
]);