Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/module-api/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,46 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig, mergeConfig } from "vitest/config";
import { defineConfig, mergeConfig, type Plugin } from "vitest/config";
import dts from "unplugin-dts/vite";
import externalGlobals from "rollup-plugin-external-globals";
import baseConfig from "@element-hq/vite-common/vite.config";

import packageJson from "./package.json" with { type: "json" };

const __dirname = dirname(fileURLToPath(import.meta.url));
const apiTypesFileName = "element-web-module-api-alpha.d.ts";

function copyPackageTypesEntry(): Plugin {
return {
name: "element-web-module-api-types-entry",
writeBundle(options): void {
const outDir = options.dir ?? resolve(__dirname, "lib");
const entryTypesPath = resolve(outDir, "index.d.ts");
const packageTypesPath = resolve(outDir, apiTypesFileName);

if (!existsSync(entryTypesPath)) return;

const source = readFileSync(entryTypesPath, "utf-8");
writeFileSync(
packageTypesPath,
source.replace("sourceMappingURL=index.d.ts.map", `sourceMappingURL=${apiTypesFileName}.map`),
);

const entryTypesMapPath = resolve(outDir, "index.d.ts.map");
if (!existsSync(entryTypesMapPath)) return;

const sourceMap = readFileSync(entryTypesMapPath, "utf-8");
writeFileSync(
`${packageTypesPath}.map`,
sourceMap.replace('"file":"index.d.ts"', `"file":"${apiTypesFileName}"`),
);
},
};
}

export default mergeConfig(
baseConfig,
Expand All @@ -31,6 +61,7 @@ export default mergeConfig(
},
plugins: [
dts(),
copyPackageTypesEntry(),
externalGlobals({
// Reuse React from the host app
react: "window.React",
Expand Down
2 changes: 2 additions & 0 deletions packages/shared-components/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const cssLayerOrder = "@layer compound-tokens, compound-web, shared-components, app-web;";
const sharedComponentsLayer = "shared-components";

const cssAssetBaseName = "element-web-shared-components";
const cssAssetFileName = "element-web-shared-components.css";

function layerCssAssets(): Plugin {
Expand Down Expand Up @@ -62,6 +63,7 @@ export default defineConfig({
// to keep the existing package.json `require` paths working.
formats: ["es", "cjs"],
fileName: (format, entryName) => `${entryName}.${format === "es" ? "js" : "umd.cjs"}`,
cssFileName: cssAssetBaseName,
},
outDir: "dist",
rolldownOptions: {
Expand Down
Loading