Files
ThreadNet-Web/packages/shared-components/vite.config.ts
T
Michael TelatynskiandGitHub 4aa1a3549e Enable oxlint restriction ruleset (#34307)
* Remove stale max-len disablements

* Remove stale camelCase & naming-convention disablements

* Remove stale ban-ts-comment disablements

* Remove stale no-var disablements

* Remove stale no-empty-property disablements

* Remove stale react rule disablements

* Remove stale no-constant-condition disablements

* Remove stale no-unused-vars disablements

* Remove stale disablements for disabled rules

* fixup camelcase

* Remove dead code

* Tidy code

* Tweak oxlint config

* Use oxlint to apply jsx/tsx extension consistently

* Fix import

* Fix imports

* Rename affected snapshots

* Update more imports

* Enable restriction ruleset

* Make code comply with new rules

* Make code comply with react/button-has-type

* Make code comply with typescript/non-nullable-type-assertion-style

* Comply with node/no-process-env

* Comply with unicorn/prefer-node-protocol

* Comply with unicorn/import-style

* Comply with unicorn/no-process-exit

* Comply with no-proto

* Comply with node/handle-callback-err

* Comply with import/no-commonjs

* Comply with node/no-path-concat

* Comply with unicorn/no-length-as-slice-end

* Comply with unicorn/no-document-cookie

* Comply with unicorn/prefer-module

* Comply with typescript/prefer-literal-enum-member

* Comply with jsx-a11y/anchor-ambiguous-text

* Tweak oxlint config

* Fix resolves

* Iterate

* Iterate

* Iterate

* Iterate

* Iterate

* Iterate

* Iterate
2026-08-04 09:15:07 +00:00

111 lines
4.6 KiB
TypeScript

/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*
*/
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { defineConfig, esmExternalRequirePlugin, type Plugin } from "vite";
import dts from "unplugin-dts/vite";
import react from "@vitejs/plugin-react";
import path from "node:path";
const cssLayerOrder = "@layer compound-tokens, compound-web, shared-components, app-web;";
const sharedComponentsLayer = "shared-components";
const cssAssetFileName = "element-web-shared-components.css";
function layerCssAssets(): Plugin {
return {
name: "element-web-shared-components-css-layer",
// Rename + layer-wrap the emitted CSS file. With multi-entry lib mode,
// vite/rolldown derives CSS filenames from the unscoped package name (dropping
// the `element-` prefix), so we rename on disk to keep the path stable for
// consumers importing `@element-hq/web-shared-components/.../*.css`.
writeBundle(options): void {
const outDir = options.dir ?? fileURLToPath(import.meta.resolve("./dist"));
const expectedPath = path.resolve(outDir, cssAssetFileName);
const renamedFromPath = path.resolve(outDir, "web-shared-components.css");
if (existsSync(renamedFromPath)) {
renameSync(renamedFromPath, expectedPath);
}
// No CSS emitted in this build (e.g. storybook's vite build doesn't produce
// the library CSS bundle), or already renamed and layered on a prior pass.
if (!existsSync(expectedPath)) return;
const source = readFileSync(expectedPath, "utf-8");
if (source.startsWith(cssLayerOrder)) return;
writeFileSync(expectedPath, `${cssLayerOrder}\n@layer ${sharedComponentsLayer} {\n${source}\n}\n`);
},
};
}
export default defineConfig({
build: {
lib: {
// Two entries: the main bundle and a standalone `numbers` utility that callers
// running outside the browser DOM (e.g. AudioWorkletGlobalScope) can import without
// pulling in the rest of the package — which transitively loads dnd-kit and
// other window/document-dependent code.
entry: {
"element-web-shared-components": fileURLToPath(import.meta.resolve("./src/index.ts")),
"numbers": fileURLToPath(import.meta.resolve("./src/core/utils/numbers.ts")),
},
name: "Element Web Shared Components",
// Multi-entry mode needs both formats explicit; UMD doesn't support multi-entry
// (single global), so we ship ES + CJS and use the `.umd.cjs` extension for CJS
// to keep the existing package.json `require` paths working.
formats: ["es", "cjs"],
fileName: (format, entryName) => `${entryName}.${format === "es" ? "js" : "umd.cjs"}`,
},
outDir: "dist",
rolldownOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: [
"@vector-im/compound-design-tokens",
"@vector-im/compound-web",
"react-virtuoso",
"react-resizable-panels",
],
plugins: [
esmExternalRequirePlugin({
external: ["react", "react-dom"],
}),
],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
"react": "react",
"@vector-im/compound-design-tokens": "compoundDesignTokens",
"@vector-im/compound-web": "compoundWeb",
"react-virtuoso": "reactVirtuoso",
"react-resizable-panels": "reactResizablePanels",
},
},
},
},
plugins: [
react(),
layerCssAssets(),
dts({
bundleTypes: {
invokeOptions: {
localBuild: !!process.env.CI,
// oxlint-disable-next-line unicorn/prefer-module
typescriptCompilerFolder: path.resolve(require.resolve("@typescript/old"), "../.."),
},
},
include: ["src/**/*.{ts,tsx}"],
exclude: ["src/**/*.test.{ts,tsx}", "src/**/*.stories.{ts,tsx}"],
copyDtsFiles: false,
}),
],
});