Skip to content
Merged
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
53 changes: 43 additions & 10 deletions packages/demo/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,53 @@ import react from "@astrojs/react";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
const site = "https://equality.eqtylab.io";

const uiSrc = resolve(__dirname, "../ui/src");

// Resolve @eqty/equality to local ui package when viewing demo
const PKG = "@eqtylab/equality";
const resolveUiFromSource = {
name: "resolve-ui-from-source",
enforce: /** @type {const} */ ("pre"),
/**
* @this {any}
* @param {string} id
* @param {string | undefined} importer
* @param {object} options
*/
async resolveId(id, importer, options) {
/** @type {string | undefined} */
let target;
if (id === `${PKG}/theme-config.css`) {
target = resolve(uiSrc, "theme/global-theme-config.css");
} else if (id === PKG) {
target = uiSrc; // directory -> index.ts
} else if (id.startsWith(`${PKG}/`)) {
target = resolve(uiSrc, id.slice(PKG.length + 1));
}
if (!target) return null;
// Delegate so Vite handles directory/extension resolution (e.g. index.ts).
const resolved = await this.resolve(target, importer, {
...options,
skipSelf: true,
});
return resolved ?? target;
},
};

// Watch the UI source
const watchUiSource = {
name: "watch-ui-source",
/** @param {{ watcher: { add: (paths: string) => void } }} server */
configureServer(server) {
server.watcher.add(uiSrc);
},
};

// https://astro.build/config
export default defineConfig({
site,
vite: {
plugins: [tailwindcss()],
ssr: {
noExternal: ["@eqtylab/equality"],
},
plugins: [tailwindcss(), resolveUiFromSource, watchUiSource],
resolve: {
alias: {
"@demo": resolve(__dirname, "./src"),
Expand All @@ -29,12 +68,6 @@ export default defineConfig({
"@demo/layouts": resolve(__dirname, "./src/layouts"),
"@demo/pages": resolve(__dirname, "./src/pages"),
"@demo/styles": resolve(__dirname, "./src/styles"),
// Resolve @eqty/equality to local ui package when viewing demo
"@eqtylab/equality/theme-config.css": resolve(
__dirname,
"../ui/src/theme/global-theme-config.css",
),
"@eqtylab/equality": resolve(__dirname, "../ui/src"),
},
},
},
Expand Down
Loading