2023-05-24 16:21:38 +00:00
|
|
|
import { defineConfig } from "tsup";
|
|
|
|
|
import { polyfillNode } from "esbuild-plugin-polyfill-node";
|
2023-05-29 02:09:44 +00:00
|
|
|
import { dependencies } from "./package.json";
|
2023-05-24 16:21:38 +00:00
|
|
|
|
2023-06-22 06:22:35 +00:00
|
|
|
const defineEnvs = (targetOptions, envs: { browser: boolean }) => {
|
|
|
|
|
targetOptions["define"] = {
|
|
|
|
|
...targetOptions["define"],
|
|
|
|
|
"process.env.IS_TEST": "false",
|
|
|
|
|
"process.env.IS_BROWSER": Boolean(envs?.browser).toString(),
|
|
|
|
|
};
|
2023-06-15 15:53:21 +00:00
|
|
|
return targetOptions;
|
2023-06-22 06:22:35 +00:00
|
|
|
};
|
2023-06-15 15:53:21 +00:00
|
|
|
|
2023-05-29 02:09:44 +00:00
|
|
|
export default async () => [
|
2023-05-24 16:21:38 +00:00
|
|
|
defineConfig({
|
2023-06-06 14:25:31 +00:00
|
|
|
name: "node-cjs",
|
2023-05-24 16:21:38 +00:00
|
|
|
entry: ["src/index.ts"],
|
|
|
|
|
platform: "node",
|
|
|
|
|
format: ["cjs"],
|
|
|
|
|
sourcemap: true,
|
2023-06-15 15:53:21 +00:00
|
|
|
esbuildOptions(options) {
|
2023-06-22 06:22:35 +00:00
|
|
|
defineEnvs(options, { browser: false });
|
2023-06-15 15:53:21 +00:00
|
|
|
},
|
2023-05-24 16:21:38 +00:00
|
|
|
clean: true,
|
|
|
|
|
}),
|
|
|
|
|
defineConfig({
|
2023-06-06 14:25:31 +00:00
|
|
|
name: "browser-iife",
|
2023-05-24 16:21:38 +00:00
|
|
|
entry: ["src/index.ts"],
|
|
|
|
|
platform: "browser",
|
|
|
|
|
format: ["iife"],
|
|
|
|
|
globalName: "Tabby",
|
2023-06-15 15:53:21 +00:00
|
|
|
treeshake: "smallest",
|
2023-06-06 14:25:31 +00:00
|
|
|
minify: true,
|
2023-05-24 16:21:38 +00:00
|
|
|
sourcemap: true,
|
2023-06-06 14:25:31 +00:00
|
|
|
esbuildPlugins: [
|
|
|
|
|
polyfillNode({
|
|
|
|
|
polyfills: { fs: true },
|
|
|
|
|
}),
|
|
|
|
|
],
|
2023-06-15 15:53:21 +00:00
|
|
|
esbuildOptions(options) {
|
2023-06-22 06:22:35 +00:00
|
|
|
defineEnvs(options, { browser: true });
|
2023-06-15 15:53:21 +00:00
|
|
|
},
|
2023-05-24 16:21:38 +00:00
|
|
|
clean: true,
|
|
|
|
|
}),
|
|
|
|
|
defineConfig({
|
2023-06-06 14:25:31 +00:00
|
|
|
name: "browser-esm",
|
|
|
|
|
entry: ["src/index.ts"],
|
|
|
|
|
platform: "browser",
|
|
|
|
|
format: ["esm"],
|
2023-06-15 15:53:21 +00:00
|
|
|
treeshake: true,
|
2023-06-06 14:25:31 +00:00
|
|
|
sourcemap: true,
|
|
|
|
|
esbuildPlugins: [
|
|
|
|
|
polyfillNode({
|
|
|
|
|
polyfills: { fs: true },
|
|
|
|
|
}),
|
|
|
|
|
],
|
2023-06-15 15:53:21 +00:00
|
|
|
esbuildOptions(options) {
|
2023-06-22 06:22:35 +00:00
|
|
|
defineEnvs(options, { browser: true });
|
2023-06-15 15:53:21 +00:00
|
|
|
},
|
2023-06-06 14:25:31 +00:00
|
|
|
clean: true,
|
|
|
|
|
}),
|
|
|
|
|
defineConfig({
|
|
|
|
|
name: "type-defs",
|
2023-05-24 16:21:38 +00:00
|
|
|
entry: ["src/index.ts"],
|
|
|
|
|
dts: {
|
|
|
|
|
only: true,
|
|
|
|
|
},
|
|
|
|
|
clean: true,
|
|
|
|
|
}),
|
|
|
|
|
defineConfig({
|
|
|
|
|
name: "cli",
|
|
|
|
|
entry: ["src/cli.ts"],
|
|
|
|
|
platform: "node",
|
2023-05-29 02:09:44 +00:00
|
|
|
noExternal: Object.keys(dependencies),
|
2023-06-15 15:53:21 +00:00
|
|
|
treeshake: "smallest",
|
2023-05-24 16:21:38 +00:00
|
|
|
minify: true,
|
2023-06-06 14:25:31 +00:00
|
|
|
sourcemap: true,
|
2023-06-15 15:53:21 +00:00
|
|
|
esbuildOptions(options) {
|
2023-06-22 06:22:35 +00:00
|
|
|
defineEnvs(options, { browser: false });
|
2023-06-15 15:53:21 +00:00
|
|
|
},
|
2023-05-24 16:21:38 +00:00
|
|
|
clean: true,
|
|
|
|
|
}),
|
|
|
|
|
];
|