Files
webstudio/packages/cli/vite.config.ts
T
Bogdan Chadkin 71f56ea7d6 refactor: bundle webstudio packages in cli (#4706)
Having all webstudio packages as dependency in CLI leads to very long
and bloated install.

Before
<img width="762" alt="Screenshot 2025-01-03 at 19 49 31"
src="https://github.com/user-attachments/assets/96624dae-c72a-4407-83ea-e56ed5d3f7d8"
/>

After
<img width="385" alt="Screenshot 2025-01-03 at 20 00 17"
src="https://github.com/user-attachments/assets/f3271c6e-07ca-47f6-9dfb-491ca68e7caf"
/>

after/before
<img width="633" alt="Screenshot 2025-01-03 at 19 58 15"
src="https://github.com/user-attachments/assets/8273072a-c71e-485c-aa39-116c9698bc8f"
/>
2025-01-04 01:02:13 +07:00

51 lines
1.1 KiB
TypeScript

import { defineConfig } from "vite";
import pkg from "./package.json";
const isExternal = (id: string, importer: string | undefined) => {
if (id.startsWith("@webstudio-is/")) {
return false;
}
if (id.startsWith("node:")) {
return true;
}
if (id.startsWith("@")) {
const packageName = id.split("/").slice(0, 2).join("/");
if (packageName in pkg.dependencies === false) {
throw Error(
`${packageName} imported from ${importer} is not found in direct dependencies`
);
}
return true;
}
if (id.includes(".") === false) {
const [packageName] = id.split("/");
if (packageName in pkg.dependencies === false) {
throw Error(
`${packageName} imported from ${importer} is not found in direct dependencies`
);
}
return true;
}
return false;
};
export default defineConfig({
// resolve only webstudio condition in tests
resolve: {
conditions: ["webstudio"],
},
build: {
minify: false,
lib: {
entry: ["src/cli.ts"],
formats: ["es"],
},
rollupOptions: {
external: isExternal,
output: {
dir: "lib",
},
},
},
});